policy update
This commit is contained in:
parent
5417c49245
commit
79bd82b802
14 changed files with 6176 additions and 5875 deletions
11660
package-lock.json
generated
11660
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -220,6 +220,11 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- input: [CallbackUrl](#CallbackUrl)
|
- input: [CallbackUrl](#CallbackUrl)
|
||||||
- output: [CallbackUrl](#CallbackUrl)
|
- output: [CallbackUrl](#CallbackUrl)
|
||||||
|
|
||||||
|
- UpdateChannelPolicy
|
||||||
|
- auth type: __Admin__
|
||||||
|
- input: [UpdateChannelPolicyRequest](#UpdateChannelPolicyRequest)
|
||||||
|
- This methods has an __empty__ __response__ body
|
||||||
|
|
||||||
- UseInviteLink
|
- UseInviteLink
|
||||||
- auth type: __GuestWithPub__
|
- auth type: __GuestWithPub__
|
||||||
- input: [UseInviteLinkRequest](#UseInviteLinkRequest)
|
- input: [UseInviteLinkRequest](#UseInviteLinkRequest)
|
||||||
|
|
@ -721,6 +726,13 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- input: [CallbackUrl](#CallbackUrl)
|
- input: [CallbackUrl](#CallbackUrl)
|
||||||
- output: [CallbackUrl](#CallbackUrl)
|
- output: [CallbackUrl](#CallbackUrl)
|
||||||
|
|
||||||
|
- UpdateChannelPolicy
|
||||||
|
- auth type: __Admin__
|
||||||
|
- http method: __post__
|
||||||
|
- http route: __/api/admin/channel/policy/update__
|
||||||
|
- input: [UpdateChannelPolicyRequest](#UpdateChannelPolicyRequest)
|
||||||
|
- This methods has an __empty__ __response__ body
|
||||||
|
|
||||||
- UseInviteLink
|
- UseInviteLink
|
||||||
- auth type: __GuestWithPub__
|
- auth type: __GuestWithPub__
|
||||||
- http method: __post__
|
- http method: __post__
|
||||||
|
|
@ -823,6 +835,13 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
### CallbackUrl
|
### CallbackUrl
|
||||||
- __url__: _string_
|
- __url__: _string_
|
||||||
|
|
||||||
|
### ChannelPolicy
|
||||||
|
- __base_fee_msat__: _number_
|
||||||
|
- __fee_rate_ppm__: _number_
|
||||||
|
- __max_htlc_msat__: _number_
|
||||||
|
- __min_htlc_msat__: _number_
|
||||||
|
- __timelock_delta__: _number_
|
||||||
|
|
||||||
### CloseChannelRequest
|
### CloseChannelRequest
|
||||||
- __force__: _boolean_
|
- __force__: _boolean_
|
||||||
- __funding_txid__: _string_
|
- __funding_txid__: _string_
|
||||||
|
|
@ -901,9 +920,6 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
### GetAppUserRequest
|
### GetAppUserRequest
|
||||||
- __user_identifier__: _string_
|
- __user_identifier__: _string_
|
||||||
|
|
||||||
### GetChannelPolicyRequest
|
|
||||||
- __channel_id__: _string_
|
|
||||||
|
|
||||||
### GetInviteTokenStateRequest
|
### GetInviteTokenStateRequest
|
||||||
- __invite_token__: _string_
|
- __invite_token__: _string_
|
||||||
|
|
||||||
|
|
@ -1039,9 +1055,11 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __active__: _boolean_
|
- __active__: _boolean_
|
||||||
- __capacity__: _number_
|
- __capacity__: _number_
|
||||||
- __channel_id__: _string_
|
- __channel_id__: _string_
|
||||||
|
- __channel_point__: _string_
|
||||||
- __label__: _string_
|
- __label__: _string_
|
||||||
- __lifetime__: _number_
|
- __lifetime__: _number_
|
||||||
- __local_balance__: _number_
|
- __local_balance__: _number_
|
||||||
|
- __policy__: _[ChannelPolicy](#ChannelPolicy)_ *this field is optional
|
||||||
- __remote_balance__: _number_
|
- __remote_balance__: _number_
|
||||||
|
|
||||||
### OpenChannelRequest
|
### OpenChannelRequest
|
||||||
|
|
@ -1138,6 +1156,10 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __amount__: _number_
|
- __amount__: _number_
|
||||||
- __invoice__: _string_
|
- __invoice__: _string_
|
||||||
|
|
||||||
|
### UpdateChannelPolicyRequest
|
||||||
|
- __policy__: _[ChannelPolicy](#ChannelPolicy)_
|
||||||
|
- __update__: _[UpdateChannelPolicyRequest_update](#UpdateChannelPolicyRequest_update)_
|
||||||
|
|
||||||
### UsageMetric
|
### UsageMetric
|
||||||
- __auth_in_nano__: _number_
|
- __auth_in_nano__: _number_
|
||||||
- __batch__: _boolean_
|
- __batch__: _boolean_
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ type Client struct {
|
||||||
SetMockAppUserBalance func(req SetMockAppUserBalanceRequest) error
|
SetMockAppUserBalance func(req SetMockAppUserBalanceRequest) error
|
||||||
SetMockInvoiceAsPaid func(req SetMockInvoiceAsPaidRequest) error
|
SetMockInvoiceAsPaid func(req SetMockInvoiceAsPaidRequest) error
|
||||||
UpdateCallbackUrl func(req CallbackUrl) (*CallbackUrl, error)
|
UpdateCallbackUrl func(req CallbackUrl) (*CallbackUrl, error)
|
||||||
|
UpdateChannelPolicy func(req UpdateChannelPolicyRequest) error
|
||||||
UseInviteLink func(req UseInviteLinkRequest) error
|
UseInviteLink func(req UseInviteLinkRequest) error
|
||||||
UserHealth func() error
|
UserHealth func() error
|
||||||
}
|
}
|
||||||
|
|
@ -1692,6 +1693,30 @@ func NewClient(params ClientParams) *Client {
|
||||||
}
|
}
|
||||||
return &res, nil
|
return &res, nil
|
||||||
},
|
},
|
||||||
|
UpdateChannelPolicy: func(req UpdateChannelPolicyRequest) error {
|
||||||
|
auth, err := params.RetrieveAdminAuth()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
finalRoute := "/api/admin/channel/policy/update"
|
||||||
|
body, err := json.Marshal(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resBody, err := doPostRequest(params.BaseURL+finalRoute, body, auth)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
result := ResultError{}
|
||||||
|
err = json.Unmarshal(resBody, &result)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if result.Status == "ERROR" {
|
||||||
|
return fmt.Errorf(result.Reason)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
UseInviteLink: func(req UseInviteLinkRequest) error {
|
UseInviteLink: func(req UseInviteLinkRequest) error {
|
||||||
auth, err := params.RetrieveGuestWithPubAuth()
|
auth, err := params.RetrieveGuestWithPubAuth()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,13 @@ type BannedAppUser struct {
|
||||||
type CallbackUrl struct {
|
type CallbackUrl struct {
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
}
|
}
|
||||||
|
type ChannelPolicy struct {
|
||||||
|
Base_fee_msat int64 `json:"base_fee_msat"`
|
||||||
|
Fee_rate_ppm int64 `json:"fee_rate_ppm"`
|
||||||
|
Max_htlc_msat int64 `json:"max_htlc_msat"`
|
||||||
|
Min_htlc_msat int64 `json:"min_htlc_msat"`
|
||||||
|
Timelock_delta int64 `json:"timelock_delta"`
|
||||||
|
}
|
||||||
type CloseChannelRequest struct {
|
type CloseChannelRequest struct {
|
||||||
Force bool `json:"force"`
|
Force bool `json:"force"`
|
||||||
Funding_txid string `json:"funding_txid"`
|
Funding_txid string `json:"funding_txid"`
|
||||||
|
|
@ -236,9 +243,6 @@ type GetAppUserLNURLInfoRequest struct {
|
||||||
type GetAppUserRequest struct {
|
type GetAppUserRequest struct {
|
||||||
User_identifier string `json:"user_identifier"`
|
User_identifier string `json:"user_identifier"`
|
||||||
}
|
}
|
||||||
type GetChannelPolicyRequest struct {
|
|
||||||
Channel_id string `json:"channel_id"`
|
|
||||||
}
|
|
||||||
type GetInviteTokenStateRequest struct {
|
type GetInviteTokenStateRequest struct {
|
||||||
Invite_token string `json:"invite_token"`
|
Invite_token string `json:"invite_token"`
|
||||||
}
|
}
|
||||||
|
|
@ -371,13 +375,15 @@ type NewInvoiceResponse struct {
|
||||||
Invoice string `json:"invoice"`
|
Invoice string `json:"invoice"`
|
||||||
}
|
}
|
||||||
type OpenChannel struct {
|
type OpenChannel struct {
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
Capacity int64 `json:"capacity"`
|
Capacity int64 `json:"capacity"`
|
||||||
Channel_id string `json:"channel_id"`
|
Channel_id string `json:"channel_id"`
|
||||||
Label string `json:"label"`
|
Channel_point string `json:"channel_point"`
|
||||||
Lifetime int64 `json:"lifetime"`
|
Label string `json:"label"`
|
||||||
Local_balance int64 `json:"local_balance"`
|
Lifetime int64 `json:"lifetime"`
|
||||||
Remote_balance int64 `json:"remote_balance"`
|
Local_balance int64 `json:"local_balance"`
|
||||||
|
Policy *ChannelPolicy `json:"policy"`
|
||||||
|
Remote_balance int64 `json:"remote_balance"`
|
||||||
}
|
}
|
||||||
type OpenChannelRequest struct {
|
type OpenChannelRequest struct {
|
||||||
Close_address string `json:"close_address"`
|
Close_address string `json:"close_address"`
|
||||||
|
|
@ -473,6 +479,10 @@ type SetMockInvoiceAsPaidRequest struct {
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
Invoice string `json:"invoice"`
|
Invoice string `json:"invoice"`
|
||||||
}
|
}
|
||||||
|
type UpdateChannelPolicyRequest struct {
|
||||||
|
Policy *ChannelPolicy `json:"policy"`
|
||||||
|
Update *UpdateChannelPolicyRequest_update `json:"update"`
|
||||||
|
}
|
||||||
type UsageMetric struct {
|
type UsageMetric struct {
|
||||||
Auth_in_nano int64 `json:"auth_in_nano"`
|
Auth_in_nano int64 `json:"auth_in_nano"`
|
||||||
Batch bool `json:"batch"`
|
Batch bool `json:"batch"`
|
||||||
|
|
@ -581,3 +591,15 @@ type NPubLinking_state struct {
|
||||||
Linking_token *string `json:"linking_token"`
|
Linking_token *string `json:"linking_token"`
|
||||||
Unlinked *Empty `json:"unlinked"`
|
Unlinked *Empty `json:"unlinked"`
|
||||||
}
|
}
|
||||||
|
type UpdateChannelPolicyRequest_update_type string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ALL UpdateChannelPolicyRequest_update_type = "all"
|
||||||
|
CHANNEL_POINT UpdateChannelPolicyRequest_update_type = "channel_point"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateChannelPolicyRequest_update struct {
|
||||||
|
Type UpdateChannelPolicyRequest_update_type `json:"type"`
|
||||||
|
All *Empty `json:"all"`
|
||||||
|
Channel_point *string `json:"channel_point"`
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1543,6 +1543,28 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
||||||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||||
})
|
})
|
||||||
|
if (!opts.allowNotImplementedMethods && !methods.UpdateChannelPolicy) throw new Error('method: UpdateChannelPolicy is not implemented')
|
||||||
|
app.post('/api/admin/channel/policy/update', async (req, res) => {
|
||||||
|
const info: Types.RequestInfo = { rpcName: 'UpdateChannelPolicy', batch: false, nostr: false, batchSize: 0}
|
||||||
|
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
||||||
|
let authCtx: Types.AuthContext = {}
|
||||||
|
try {
|
||||||
|
if (!methods.UpdateChannelPolicy) throw new Error('method: UpdateChannelPolicy is not implemented')
|
||||||
|
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
||||||
|
authCtx = authContext
|
||||||
|
stats.guard = process.hrtime.bigint()
|
||||||
|
const request = req.body
|
||||||
|
const error = Types.UpdateChannelPolicyRequestValidate(request)
|
||||||
|
stats.validate = process.hrtime.bigint()
|
||||||
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
||||||
|
const query = req.query
|
||||||
|
const params = req.params
|
||||||
|
await methods.UpdateChannelPolicy({rpcName:'UpdateChannelPolicy', ctx:authContext , req: request})
|
||||||
|
stats.handle = process.hrtime.bigint()
|
||||||
|
res.json({status: 'OK'})
|
||||||
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||||
|
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||||
|
})
|
||||||
if (!opts.allowNotImplementedMethods && !methods.UseInviteLink) throw new Error('method: UseInviteLink is not implemented')
|
if (!opts.allowNotImplementedMethods && !methods.UseInviteLink) throw new Error('method: UseInviteLink is not implemented')
|
||||||
app.post('/api/guest/invite', async (req, res) => {
|
app.post('/api/guest/invite', async (req, res) => {
|
||||||
const info: Types.RequestInfo = { rpcName: 'UseInviteLink', batch: false, nostr: false, batchSize: 0}
|
const info: Types.RequestInfo = { rpcName: 'UseInviteLink', batch: false, nostr: false, batchSize: 0}
|
||||||
|
|
|
||||||
|
|
@ -810,6 +810,17 @@ export default (params: ClientParams) => ({
|
||||||
}
|
}
|
||||||
return { status: 'ERROR', reason: 'invalid response' }
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
},
|
},
|
||||||
|
UpdateChannelPolicy: async (request: Types.UpdateChannelPolicyRequest): Promise<ResultError | ({ status: 'OK' })> => {
|
||||||
|
const auth = await params.retrieveAdminAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveAdminAuth() returned null')
|
||||||
|
let finalRoute = '/api/admin/channel/policy/update'
|
||||||
|
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' })> => {
|
UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' })> => {
|
||||||
const auth = await params.retrieveGuestWithPubAuth()
|
const auth = await params.retrieveGuestWithPubAuth()
|
||||||
if (auth === null) throw new Error('retrieveGuestWithPubAuth() returned null')
|
if (auth === null) throw new Error('retrieveGuestWithPubAuth() returned null')
|
||||||
|
|
|
||||||
|
|
@ -594,6 +594,18 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
|
||||||
}
|
}
|
||||||
return { status: 'ERROR', reason: 'invalid response' }
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
},
|
},
|
||||||
|
UpdateChannelPolicy: async (request: Types.UpdateChannelPolicyRequest): Promise<ResultError | ({ status: 'OK' })> => {
|
||||||
|
const auth = await params.retrieveNostrAdminAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null')
|
||||||
|
const nostrRequest: NostrRequest = {}
|
||||||
|
nostrRequest.body = request
|
||||||
|
const data = await send(params.pubDestination, {rpcName:'UpdateChannelPolicy',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' })> => {
|
UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise<ResultError | ({ status: 'OK' })> => {
|
||||||
const auth = await params.retrieveNostrGuestWithPubAuth()
|
const auth = await params.retrieveNostrGuestWithPubAuth()
|
||||||
if (auth === null) throw new Error('retrieveNostrGuestWithPubAuth() returned null')
|
if (auth === null) throw new Error('retrieveNostrGuestWithPubAuth() returned null')
|
||||||
|
|
|
||||||
|
|
@ -912,6 +912,22 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||||
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||||
break
|
break
|
||||||
|
case 'UpdateChannelPolicy':
|
||||||
|
try {
|
||||||
|
if (!methods.UpdateChannelPolicy) throw new Error('method: UpdateChannelPolicy is not implemented')
|
||||||
|
const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier)
|
||||||
|
stats.guard = process.hrtime.bigint()
|
||||||
|
authCtx = authContext
|
||||||
|
const request = req.body
|
||||||
|
const error = Types.UpdateChannelPolicyRequestValidate(request)
|
||||||
|
stats.validate = process.hrtime.bigint()
|
||||||
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
|
await methods.UpdateChannelPolicy({rpcName:'UpdateChannelPolicy', ctx:authContext , req: request})
|
||||||
|
stats.handle = process.hrtime.bigint()
|
||||||
|
res({status: 'OK'})
|
||||||
|
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||||
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||||
|
break
|
||||||
case 'UseInviteLink':
|
case 'UseInviteLink':
|
||||||
try {
|
try {
|
||||||
if (!methods.UseInviteLink) throw new Error('method: UseInviteLink is not implemented')
|
if (!methods.UseInviteLink) throw new Error('method: UseInviteLink is not implemented')
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ export type RequestMetric = AuthContext & RequestInfo & RequestStats & { error?:
|
||||||
export type AdminContext = {
|
export type AdminContext = {
|
||||||
admin_id: string
|
admin_id: string
|
||||||
}
|
}
|
||||||
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input
|
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | UpdateChannelPolicy_Input
|
||||||
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output
|
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | UpdateChannelPolicy_Output
|
||||||
export type AppContext = {
|
export type AppContext = {
|
||||||
app_id: string
|
app_id: string
|
||||||
}
|
}
|
||||||
|
|
@ -249,6 +249,9 @@ export type SetMockInvoiceAsPaid_Output = ResultError | { status: 'OK' }
|
||||||
export type UpdateCallbackUrl_Input = {rpcName:'UpdateCallbackUrl', req: CallbackUrl}
|
export type UpdateCallbackUrl_Input = {rpcName:'UpdateCallbackUrl', req: CallbackUrl}
|
||||||
export type UpdateCallbackUrl_Output = ResultError | ({ status: 'OK' } & CallbackUrl)
|
export type UpdateCallbackUrl_Output = ResultError | ({ status: 'OK' } & CallbackUrl)
|
||||||
|
|
||||||
|
export type UpdateChannelPolicy_Input = {rpcName:'UpdateChannelPolicy', req: UpdateChannelPolicyRequest}
|
||||||
|
export type UpdateChannelPolicy_Output = ResultError | { status: 'OK' }
|
||||||
|
|
||||||
export type UseInviteLink_Input = {rpcName:'UseInviteLink', req: UseInviteLinkRequest}
|
export type UseInviteLink_Input = {rpcName:'UseInviteLink', req: UseInviteLinkRequest}
|
||||||
export type UseInviteLink_Output = ResultError | { status: 'OK' }
|
export type UseInviteLink_Output = ResultError | { status: 'OK' }
|
||||||
|
|
||||||
|
|
@ -318,6 +321,7 @@ export type ServerMethods = {
|
||||||
SetMockAppUserBalance?: (req: SetMockAppUserBalance_Input & {ctx: AppContext }) => Promise<void>
|
SetMockAppUserBalance?: (req: SetMockAppUserBalance_Input & {ctx: AppContext }) => Promise<void>
|
||||||
SetMockInvoiceAsPaid?: (req: SetMockInvoiceAsPaid_Input & {ctx: GuestContext }) => Promise<void>
|
SetMockInvoiceAsPaid?: (req: SetMockInvoiceAsPaid_Input & {ctx: GuestContext }) => Promise<void>
|
||||||
UpdateCallbackUrl?: (req: UpdateCallbackUrl_Input & {ctx: UserContext }) => Promise<CallbackUrl>
|
UpdateCallbackUrl?: (req: UpdateCallbackUrl_Input & {ctx: UserContext }) => Promise<CallbackUrl>
|
||||||
|
UpdateChannelPolicy?: (req: UpdateChannelPolicy_Input & {ctx: AdminContext }) => Promise<void>
|
||||||
UseInviteLink?: (req: UseInviteLink_Input & {ctx: GuestWithPubContext }) => Promise<void>
|
UseInviteLink?: (req: UseInviteLink_Input & {ctx: GuestWithPubContext }) => Promise<void>
|
||||||
UserHealth?: (req: UserHealth_Input & {ctx: UserContext }) => Promise<void>
|
UserHealth?: (req: UserHealth_Input & {ctx: UserContext }) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
@ -846,6 +850,44 @@ export const CallbackUrlValidate = (o?: CallbackUrl, opts: CallbackUrlOptions =
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ChannelPolicy = {
|
||||||
|
base_fee_msat: number
|
||||||
|
fee_rate_ppm: number
|
||||||
|
max_htlc_msat: number
|
||||||
|
min_htlc_msat: number
|
||||||
|
timelock_delta: number
|
||||||
|
}
|
||||||
|
export const ChannelPolicyOptionalFields: [] = []
|
||||||
|
export type ChannelPolicyOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
base_fee_msat_CustomCheck?: (v: number) => boolean
|
||||||
|
fee_rate_ppm_CustomCheck?: (v: number) => boolean
|
||||||
|
max_htlc_msat_CustomCheck?: (v: number) => boolean
|
||||||
|
min_htlc_msat_CustomCheck?: (v: number) => boolean
|
||||||
|
timelock_delta_CustomCheck?: (v: number) => boolean
|
||||||
|
}
|
||||||
|
export const ChannelPolicyValidate = (o?: ChannelPolicy, opts: ChannelPolicyOptions = {}, path: string = 'ChannelPolicy::root.'): Error | null => {
|
||||||
|
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||||
|
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||||
|
|
||||||
|
if (typeof o.base_fee_msat !== 'number') return new Error(`${path}.base_fee_msat: is not a number`)
|
||||||
|
if (opts.base_fee_msat_CustomCheck && !opts.base_fee_msat_CustomCheck(o.base_fee_msat)) return new Error(`${path}.base_fee_msat: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.fee_rate_ppm !== 'number') return new Error(`${path}.fee_rate_ppm: is not a number`)
|
||||||
|
if (opts.fee_rate_ppm_CustomCheck && !opts.fee_rate_ppm_CustomCheck(o.fee_rate_ppm)) return new Error(`${path}.fee_rate_ppm: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.max_htlc_msat !== 'number') return new Error(`${path}.max_htlc_msat: is not a number`)
|
||||||
|
if (opts.max_htlc_msat_CustomCheck && !opts.max_htlc_msat_CustomCheck(o.max_htlc_msat)) return new Error(`${path}.max_htlc_msat: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.min_htlc_msat !== 'number') return new Error(`${path}.min_htlc_msat: is not a number`)
|
||||||
|
if (opts.min_htlc_msat_CustomCheck && !opts.min_htlc_msat_CustomCheck(o.min_htlc_msat)) return new Error(`${path}.min_htlc_msat: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.timelock_delta !== 'number') return new Error(`${path}.timelock_delta: is not a number`)
|
||||||
|
if (opts.timelock_delta_CustomCheck && !opts.timelock_delta_CustomCheck(o.timelock_delta)) return new Error(`${path}.timelock_delta: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
export type CloseChannelRequest = {
|
export type CloseChannelRequest = {
|
||||||
force: boolean
|
force: boolean
|
||||||
funding_txid: string
|
funding_txid: string
|
||||||
|
|
@ -1318,24 +1360,6 @@ export const GetAppUserRequestValidate = (o?: GetAppUserRequest, opts: GetAppUse
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GetChannelPolicyRequest = {
|
|
||||||
channel_id: string
|
|
||||||
}
|
|
||||||
export const GetChannelPolicyRequestOptionalFields: [] = []
|
|
||||||
export type GetChannelPolicyRequestOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
channel_id_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const GetChannelPolicyRequestValidate = (o?: GetChannelPolicyRequest, opts: GetChannelPolicyRequestOptions = {}, path: string = 'GetChannelPolicyRequest::root.'): Error | null => {
|
|
||||||
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
|
||||||
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
|
||||||
|
|
||||||
if (typeof o.channel_id !== 'string') return new Error(`${path}.channel_id: is not a string`)
|
|
||||||
if (opts.channel_id_CustomCheck && !opts.channel_id_CustomCheck(o.channel_id)) return new Error(`${path}.channel_id: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type GetInviteTokenStateRequest = {
|
export type GetInviteTokenStateRequest = {
|
||||||
invite_token: string
|
invite_token: string
|
||||||
}
|
}
|
||||||
|
|
@ -2143,20 +2167,25 @@ export type OpenChannel = {
|
||||||
active: boolean
|
active: boolean
|
||||||
capacity: number
|
capacity: number
|
||||||
channel_id: string
|
channel_id: string
|
||||||
|
channel_point: string
|
||||||
label: string
|
label: string
|
||||||
lifetime: number
|
lifetime: number
|
||||||
local_balance: number
|
local_balance: number
|
||||||
|
policy?: ChannelPolicy
|
||||||
remote_balance: number
|
remote_balance: number
|
||||||
}
|
}
|
||||||
export const OpenChannelOptionalFields: [] = []
|
export type OpenChannelOptionalField = 'policy'
|
||||||
|
export const OpenChannelOptionalFields: OpenChannelOptionalField[] = ['policy']
|
||||||
export type OpenChannelOptions = OptionsBaseMessage & {
|
export type OpenChannelOptions = OptionsBaseMessage & {
|
||||||
checkOptionalsAreSet?: []
|
checkOptionalsAreSet?: OpenChannelOptionalField[]
|
||||||
active_CustomCheck?: (v: boolean) => boolean
|
active_CustomCheck?: (v: boolean) => boolean
|
||||||
capacity_CustomCheck?: (v: number) => boolean
|
capacity_CustomCheck?: (v: number) => boolean
|
||||||
channel_id_CustomCheck?: (v: string) => boolean
|
channel_id_CustomCheck?: (v: string) => boolean
|
||||||
|
channel_point_CustomCheck?: (v: string) => boolean
|
||||||
label_CustomCheck?: (v: string) => boolean
|
label_CustomCheck?: (v: string) => boolean
|
||||||
lifetime_CustomCheck?: (v: number) => boolean
|
lifetime_CustomCheck?: (v: number) => boolean
|
||||||
local_balance_CustomCheck?: (v: number) => boolean
|
local_balance_CustomCheck?: (v: number) => boolean
|
||||||
|
policy_Options?: ChannelPolicyOptions
|
||||||
remote_balance_CustomCheck?: (v: number) => boolean
|
remote_balance_CustomCheck?: (v: number) => boolean
|
||||||
}
|
}
|
||||||
export const OpenChannelValidate = (o?: OpenChannel, opts: OpenChannelOptions = {}, path: string = 'OpenChannel::root.'): Error | null => {
|
export const OpenChannelValidate = (o?: OpenChannel, opts: OpenChannelOptions = {}, path: string = 'OpenChannel::root.'): Error | null => {
|
||||||
|
|
@ -2172,6 +2201,9 @@ export const OpenChannelValidate = (o?: OpenChannel, opts: OpenChannelOptions =
|
||||||
if (typeof o.channel_id !== 'string') return new Error(`${path}.channel_id: is not a string`)
|
if (typeof o.channel_id !== 'string') return new Error(`${path}.channel_id: is not a string`)
|
||||||
if (opts.channel_id_CustomCheck && !opts.channel_id_CustomCheck(o.channel_id)) return new Error(`${path}.channel_id: custom check failed`)
|
if (opts.channel_id_CustomCheck && !opts.channel_id_CustomCheck(o.channel_id)) return new Error(`${path}.channel_id: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.channel_point !== 'string') return new Error(`${path}.channel_point: is not a string`)
|
||||||
|
if (opts.channel_point_CustomCheck && !opts.channel_point_CustomCheck(o.channel_point)) return new Error(`${path}.channel_point: custom check failed`)
|
||||||
|
|
||||||
if (typeof o.label !== 'string') return new Error(`${path}.label: is not a string`)
|
if (typeof o.label !== 'string') return new Error(`${path}.label: is not a string`)
|
||||||
if (opts.label_CustomCheck && !opts.label_CustomCheck(o.label)) return new Error(`${path}.label: custom check failed`)
|
if (opts.label_CustomCheck && !opts.label_CustomCheck(o.label)) return new Error(`${path}.label: custom check failed`)
|
||||||
|
|
||||||
|
|
@ -2181,6 +2213,12 @@ export const OpenChannelValidate = (o?: OpenChannel, opts: OpenChannelOptions =
|
||||||
if (typeof o.local_balance !== 'number') return new Error(`${path}.local_balance: is not a number`)
|
if (typeof o.local_balance !== 'number') return new Error(`${path}.local_balance: is not a number`)
|
||||||
if (opts.local_balance_CustomCheck && !opts.local_balance_CustomCheck(o.local_balance)) return new Error(`${path}.local_balance: custom check failed`)
|
if (opts.local_balance_CustomCheck && !opts.local_balance_CustomCheck(o.local_balance)) return new Error(`${path}.local_balance: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.policy === 'object' || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('policy')) {
|
||||||
|
const policyErr = ChannelPolicyValidate(o.policy, opts.policy_Options, `${path}.policy`)
|
||||||
|
if (policyErr !== null) return policyErr
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (typeof o.remote_balance !== 'number') return new Error(`${path}.remote_balance: is not a number`)
|
if (typeof o.remote_balance !== 'number') return new Error(`${path}.remote_balance: is not a number`)
|
||||||
if (opts.remote_balance_CustomCheck && !opts.remote_balance_CustomCheck(o.remote_balance)) return new Error(`${path}.remote_balance: custom check failed`)
|
if (opts.remote_balance_CustomCheck && !opts.remote_balance_CustomCheck(o.remote_balance)) return new Error(`${path}.remote_balance: custom check failed`)
|
||||||
|
|
||||||
|
|
@ -2717,6 +2755,31 @@ export const SetMockInvoiceAsPaidRequestValidate = (o?: SetMockInvoiceAsPaidRequ
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type UpdateChannelPolicyRequest = {
|
||||||
|
policy: ChannelPolicy
|
||||||
|
update: UpdateChannelPolicyRequest_update
|
||||||
|
}
|
||||||
|
export const UpdateChannelPolicyRequestOptionalFields: [] = []
|
||||||
|
export type UpdateChannelPolicyRequestOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
policy_Options?: ChannelPolicyOptions
|
||||||
|
update_Options?: UpdateChannelPolicyRequest_updateOptions
|
||||||
|
}
|
||||||
|
export const UpdateChannelPolicyRequestValidate = (o?: UpdateChannelPolicyRequest, opts: UpdateChannelPolicyRequestOptions = {}, path: string = 'UpdateChannelPolicyRequest::root.'): Error | null => {
|
||||||
|
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||||
|
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||||
|
|
||||||
|
const policyErr = ChannelPolicyValidate(o.policy, opts.policy_Options, `${path}.policy`)
|
||||||
|
if (policyErr !== null) return policyErr
|
||||||
|
|
||||||
|
|
||||||
|
const updateErr = UpdateChannelPolicyRequest_updateValidate(o.update, opts.update_Options, `${path}.update`)
|
||||||
|
if (updateErr !== null) return updateErr
|
||||||
|
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
export type UsageMetric = {
|
export type UsageMetric = {
|
||||||
auth_in_nano: number
|
auth_in_nano: number
|
||||||
batch: boolean
|
batch: boolean
|
||||||
|
|
@ -3184,6 +3247,42 @@ export const NPubLinking_stateValidate = (o?: NPubLinking_state, opts:NPubLinkin
|
||||||
if (unlinkedErr !== null) return unlinkedErr
|
if (unlinkedErr !== null) return unlinkedErr
|
||||||
|
|
||||||
|
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return new Error(path + ': unknown type '+ stringType)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
export enum UpdateChannelPolicyRequest_update_type {
|
||||||
|
ALL = 'all',
|
||||||
|
CHANNEL_POINT = 'channel_point',
|
||||||
|
}
|
||||||
|
export const enumCheckUpdateChannelPolicyRequest_update_type = (e?: UpdateChannelPolicyRequest_update_type): boolean => {
|
||||||
|
for (const v in UpdateChannelPolicyRequest_update_type) if (e === v) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
export type UpdateChannelPolicyRequest_update =
|
||||||
|
{type:UpdateChannelPolicyRequest_update_type.ALL, all:Empty}|
|
||||||
|
{type:UpdateChannelPolicyRequest_update_type.CHANNEL_POINT, channel_point:string}
|
||||||
|
|
||||||
|
export type UpdateChannelPolicyRequest_updateOptions = {
|
||||||
|
all_Options?: EmptyOptions
|
||||||
|
channel_point_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const UpdateChannelPolicyRequest_updateValidate = (o?: UpdateChannelPolicyRequest_update, opts:UpdateChannelPolicyRequest_updateOptions = {}, path: string = 'UpdateChannelPolicyRequest_update::root.'): Error | null => {
|
||||||
|
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||||
|
const stringType: string = o.type
|
||||||
|
switch (o.type) {
|
||||||
|
case UpdateChannelPolicyRequest_update_type.ALL:
|
||||||
|
const allErr = EmptyValidate(o.all, opts.all_Options, `${path}.all`)
|
||||||
|
if (allErr !== null) return allErr
|
||||||
|
|
||||||
|
|
||||||
|
break
|
||||||
|
case UpdateChannelPolicyRequest_update_type.CHANNEL_POINT:
|
||||||
|
if (typeof o.channel_point !== 'string') return new Error(`${path}.channel_point: is not a string`)
|
||||||
|
if (opts.channel_point_CustomCheck && !opts.channel_point_CustomCheck(o.channel_point)) return new Error(`${path}.channel_point: custom check failed`)
|
||||||
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return new Error(path + ': unknown type '+ stringType)
|
return new Error(path + ': unknown type '+ stringType)
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,13 @@ service LightningPub {
|
||||||
option (nostr) = true;
|
option (nostr) = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpc UpdateChannelPolicy (structs.UpdateChannelPolicyRequest) returns (structs.Empty) {
|
||||||
|
option (auth_type) = "Admin";
|
||||||
|
option (http_method) = "post";
|
||||||
|
option (http_route) = "/api/admin/channel/policy/update";
|
||||||
|
option (nostr) = true;
|
||||||
|
}
|
||||||
|
|
||||||
rpc OpenChannel(structs.OpenChannelRequest) returns (structs.OpenChannelResponse) {
|
rpc OpenChannel(structs.OpenChannelRequest) returns (structs.OpenChannelResponse) {
|
||||||
option (auth_type) = "Admin";
|
option (auth_type) = "Admin";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,22 @@ message RoutingEvent {
|
||||||
bool forward_fail_event = 12;
|
bool forward_fail_event = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ChannelPolicy {
|
||||||
|
int64 base_fee_msat= 1;
|
||||||
|
int64 fee_rate_ppm = 2;
|
||||||
|
int64 max_htlc_msat = 3;
|
||||||
|
int64 min_htlc_msat = 4;
|
||||||
|
int64 timelock_delta = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateChannelPolicyRequest {
|
||||||
|
oneof update {
|
||||||
|
string channel_point = 1;
|
||||||
|
Empty all = 2;
|
||||||
|
}
|
||||||
|
ChannelPolicy policy = 3;
|
||||||
|
}
|
||||||
|
|
||||||
message OpenChannel {
|
message OpenChannel {
|
||||||
string channel_id = 1;
|
string channel_id = 1;
|
||||||
int64 capacity = 2;
|
int64 capacity = 2;
|
||||||
|
|
@ -96,6 +112,8 @@ message OpenChannel {
|
||||||
int64 local_balance=5;
|
int64 local_balance=5;
|
||||||
int64 remote_balance = 6;
|
int64 remote_balance = 6;
|
||||||
string label = 7;
|
string label = 7;
|
||||||
|
string channel_point = 8;
|
||||||
|
optional ChannelPolicy policy = 9;
|
||||||
}
|
}
|
||||||
message ClosedChannel {
|
message ClosedChannel {
|
||||||
string channel_id = 1;
|
string channel_id = 1;
|
||||||
|
|
@ -131,10 +149,6 @@ message LndChannels {
|
||||||
repeated OpenChannel open_channels = 1;
|
repeated OpenChannel open_channels = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetChannelPolicyRequest {
|
|
||||||
string channel_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
message OpenChannelRequest{
|
message OpenChannelRequest{
|
||||||
|
|
|
||||||
|
|
@ -385,6 +385,23 @@ export default class {
|
||||||
return res.response
|
return res.response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async UpdateChannelPolicy(chanPoint: string, policy: Types.ChannelPolicy) {
|
||||||
|
const split = chanPoint.split(':')
|
||||||
|
|
||||||
|
const res = await this.lightning.updateChannelPolicy({
|
||||||
|
scope: policy ? { oneofKind: 'chanPoint', chanPoint: { fundingTxid: { oneofKind: 'fundingTxidStr', fundingTxidStr: split[0] }, outputIndex: Number(split[1]) } } : { oneofKind: 'global', global: true },
|
||||||
|
baseFeeMsat: BigInt(policy.base_fee_msat),
|
||||||
|
feeRate: 0,
|
||||||
|
maxHtlcMsat: BigInt(policy.max_htlc_msat),
|
||||||
|
minHtlcMsat: BigInt(policy.min_htlc_msat),
|
||||||
|
timeLockDelta: policy.timelock_delta,
|
||||||
|
inboundFee: undefined,
|
||||||
|
feeRatePpm: policy.fee_rate_ppm,
|
||||||
|
minHtlcMsatSpecified: policy.min_htlc_msat > 0,
|
||||||
|
}, DeadLineMetadata())
|
||||||
|
return res.response
|
||||||
|
}
|
||||||
|
|
||||||
async GetChannelBalance() {
|
async GetChannelBalance() {
|
||||||
const res = await this.lightning.channelBalance({}, DeadLineMetadata())
|
const res = await this.lightning.channelBalance({}, DeadLineMetadata())
|
||||||
return res.response
|
return res.response
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import fs, { watchFile } from "fs";
|
import fs, { watchFile } from "fs";
|
||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
import { getLogger } from "../helpers/logger.js";
|
import { ERROR, getLogger } from "../helpers/logger.js";
|
||||||
import { MainSettings, getDataPath } from "./settings.js";
|
import { MainSettings, getDataPath } from "./settings.js";
|
||||||
import Storage from "../storage/index.js";
|
import Storage from "../storage/index.js";
|
||||||
import * as Types from '../../../proto/autogenerated/ts/types.js'
|
import * as Types from '../../../proto/autogenerated/ts/types.js'
|
||||||
|
|
@ -146,18 +146,43 @@ export class AdminManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
ListChannels = async (): Promise<Types.LndChannels> => {
|
ListChannels = async (): Promise<Types.LndChannels> => {
|
||||||
const channels = await this.lnd.ListChannels(true)
|
const { channels } = await this.lnd.ListChannels(true)
|
||||||
|
const { identityPubkey } = await this.lnd.GetInfo()
|
||||||
|
const openChannels = await Promise.all(channels.map(async c => {
|
||||||
|
const info = await this.lnd.GetChannelInfo(c.chanId)
|
||||||
|
const policies = [{ pub: info.node1Pub, policy: info.node1Policy }, { pub: info.node2Pub, policy: info.node2Policy }]
|
||||||
|
const myPolicy = policies.find(p => p.pub === identityPubkey)?.policy
|
||||||
|
const policy: Types.ChannelPolicy | undefined = myPolicy ? {
|
||||||
|
base_fee_msat: Number(myPolicy.feeBaseMsat),
|
||||||
|
fee_rate_ppm: Number(myPolicy.feeRateMilliMsat),
|
||||||
|
timelock_delta: Number(myPolicy.timeLockDelta),
|
||||||
|
max_htlc_msat: Number(myPolicy.maxHtlcMsat),
|
||||||
|
min_htlc_msat: Number(myPolicy.minHtlc),
|
||||||
|
|
||||||
return {
|
} : undefined
|
||||||
open_channels: channels.channels.map(c => ({
|
return {
|
||||||
|
channel_point: c.channelPoint,
|
||||||
active: c.active,
|
active: c.active,
|
||||||
capacity: Number(c.capacity),
|
capacity: Number(c.capacity),
|
||||||
local_balance: Number(c.localBalance),
|
local_balance: Number(c.localBalance),
|
||||||
remote_balance: Number(c.remoteBalance),
|
remote_balance: Number(c.remoteBalance),
|
||||||
channel_id: c.chanId,
|
channel_id: c.chanId,
|
||||||
label: c.peerAlias || c.remotePubkey,
|
label: c.peerAlias || c.remotePubkey,
|
||||||
lifetime: Number(c.lifetime)
|
lifetime: Number(c.lifetime),
|
||||||
}))
|
policy,
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return {
|
||||||
|
open_channels: openChannels
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async UpdateChannelPolicy(req: Types.UpdateChannelPolicyRequest): Promise<void> {
|
||||||
|
const chanPoint = req.update.type === Types.UpdateChannelPolicyRequest_update_type.CHANNEL_POINT ? req.update.channel_point : ""
|
||||||
|
const res = await this.lnd.UpdateChannelPolicy(chanPoint, req.policy)
|
||||||
|
if (res.failedUpdates) {
|
||||||
|
this.log(ERROR, "failed to update policy", res.failedUpdates)
|
||||||
|
throw new Error("failed to update policy")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,15 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
||||||
if (err != null) throw new Error(err.message)
|
if (err != null) throw new Error(err.message)
|
||||||
return mainHandler.adminManager.AddPeer(req)
|
return mainHandler.adminManager.AddPeer(req)
|
||||||
},
|
},
|
||||||
|
UpdateChannelPolicy: async ({ ctx, req }) => {
|
||||||
|
const err = Types.UpdateChannelPolicyRequestValidate(req, {
|
||||||
|
update_Options: {
|
||||||
|
channel_point_CustomCheck: cp => cp !== '',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (err != null) throw new Error(err.message)
|
||||||
|
return mainHandler.adminManager.UpdateChannelPolicy(req)
|
||||||
|
},
|
||||||
OpenChannel: async ({ ctx, req }) => {
|
OpenChannel: async ({ ctx, req }) => {
|
||||||
const err = Types.OpenChannelRequestValidate(req, {
|
const err = Types.OpenChannelRequestValidate(req, {
|
||||||
node_pubkey_CustomCheck: pubkey => pubkey !== '',
|
node_pubkey_CustomCheck: pubkey => pubkey !== '',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue