bump fee api
This commit is contained in:
parent
67f9dfde8b
commit
169284021f
12 changed files with 175 additions and 3 deletions
|
|
@ -58,6 +58,11 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- This methods has an __empty__ __request__ body
|
||||
- This methods has an __empty__ __response__ body
|
||||
|
||||
- BumpTx
|
||||
- auth type: __Admin__
|
||||
- input: [BumpTx](#BumpTx)
|
||||
- This methods has an __empty__ __response__ body
|
||||
|
||||
- CloseChannel
|
||||
- auth type: __Admin__
|
||||
- input: [CloseChannelRequest](#CloseChannelRequest)
|
||||
|
|
@ -509,6 +514,13 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- This methods has an __empty__ __request__ body
|
||||
- This methods has an __empty__ __response__ body
|
||||
|
||||
- BumpTx
|
||||
- auth type: __Admin__
|
||||
- http method: __post__
|
||||
- http route: __/api/admin/tx/bump__
|
||||
- input: [BumpTx](#BumpTx)
|
||||
- This methods has an __empty__ __response__ body
|
||||
|
||||
- CloseChannel
|
||||
- auth type: __Admin__
|
||||
- http method: __post__
|
||||
|
|
@ -1241,6 +1253,11 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __nextRelay__: _string_ *this field is optional
|
||||
- __type__: _string_
|
||||
|
||||
### BumpTx
|
||||
- __output_index__: _number_
|
||||
- __sat_per_vbyte__: _number_
|
||||
- __txid__: _string_
|
||||
|
||||
### BundleData
|
||||
- __available_chunks__: ARRAY of: _number_
|
||||
- __base_64_data__: ARRAY of: _string_
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ type Client struct {
|
|||
BanDebit func(req DebitOperation) error
|
||||
BanUser func(req BanUserRequest) (*BanUserResponse, error)
|
||||
// batching method: BatchUser not implemented
|
||||
BumpTx func(req BumpTx) error
|
||||
CloseChannel func(req CloseChannelRequest) (*CloseChannelResponse, error)
|
||||
CreateOneTimeInviteLink func(req CreateOneTimeInviteLinkRequest) (*CreateOneTimeInviteLinkResponse, error)
|
||||
DecodeInvoice func(req DecodeInvoiceRequest) (*DecodeInvoiceResponse, error)
|
||||
|
|
@ -465,6 +466,30 @@ func NewClient(params ClientParams) *Client {
|
|||
return &res, nil
|
||||
},
|
||||
// batching method: BatchUser not implemented
|
||||
BumpTx: func(req BumpTx) error {
|
||||
auth, err := params.RetrieveAdminAuth()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
finalRoute := "/api/admin/tx/bump"
|
||||
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
|
||||
},
|
||||
CloseChannel: func(req CloseChannelRequest) (*CloseChannelResponse, error) {
|
||||
auth, err := params.RetrieveAdminAuth()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -213,6 +213,11 @@ type BeaconData struct {
|
|||
Nextrelay string `json:"nextRelay"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
type BumpTx struct {
|
||||
Output_index int64 `json:"output_index"`
|
||||
Sat_per_vbyte int64 `json:"sat_per_vbyte"`
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
type BundleData struct {
|
||||
Available_chunks []int64 `json:"available_chunks"`
|
||||
Base_64_data []string `json:"base_64_data"`
|
||||
|
|
|
|||
|
|
@ -693,6 +693,28 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
opts.metricsCallback([{ ...info, ...stats, ...ctx }, ...callsMetrics])
|
||||
} 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.BumpTx) throw new Error('method: BumpTx is not implemented')
|
||||
app.post('/api/admin/tx/bump', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'BumpTx', 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.BumpTx) throw new Error('method: BumpTx 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.BumpTxValidate(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.BumpTx({rpcName:'BumpTx', 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.CloseChannel) throw new Error('method: CloseChannel is not implemented')
|
||||
app.post('/api/admin/channel/close', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'CloseChannel', batch: false, nostr: false, batchSize: 0}
|
||||
|
|
|
|||
|
|
@ -176,6 +176,17 @@ export default (params: ClientParams) => ({
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
BumpTx: async (request: Types.BumpTx): Promise<ResultError | ({ status: 'OK' })> => {
|
||||
const auth = await params.retrieveAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveAdminAuth() returned null')
|
||||
let finalRoute = '/api/admin/tx/bump'
|
||||
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' }
|
||||
},
|
||||
CloseChannel: async (request: Types.CloseChannelRequest): Promise<ResultError | ({ status: 'OK' }& Types.CloseChannelResponse)> => {
|
||||
const auth = await params.retrieveAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveAdminAuth() returned null')
|
||||
|
|
|
|||
|
|
@ -137,6 +137,18 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
BumpTx: async (request: Types.BumpTx): 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:'BumpTx',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' }
|
||||
},
|
||||
CloseChannel: async (request: Types.CloseChannelRequest): Promise<ResultError | ({ status: 'OK' }& Types.CloseChannelResponse)> => {
|
||||
const auth = await params.retrieveNostrAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null')
|
||||
|
|
|
|||
|
|
@ -575,6 +575,22 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
|||
opts.metricsCallback([{ ...info, ...stats, ...ctx }, ...callsMetrics])
|
||||
}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 'BumpTx':
|
||||
try {
|
||||
if (!methods.BumpTx) throw new Error('method: BumpTx 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.BumpTxValidate(request)
|
||||
stats.validate = process.hrtime.bigint()
|
||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||
await methods.BumpTx({rpcName:'BumpTx', 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 'CloseChannel':
|
||||
try {
|
||||
if (!methods.CloseChannel) throw new Error('method: CloseChannel is not implemented')
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ export type RequestMetric = AuthContext & RequestInfo & RequestStats & { error?:
|
|||
export type AdminContext = {
|
||||
admin_id: string
|
||||
}
|
||||
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetAdminInvoiceSwapQuotes_Input | GetAdminTransactionSwapQuotes_Input | GetAssetsAndLiabilities_Input | GetInviteLinkState_Input | GetSeed_Input | ListAdminInvoiceSwaps_Input | ListAdminTxSwaps_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | PayAdminInvoiceSwap_Input | PayAdminTransactionSwap_Input | RefundAdminInvoiceSwap_Input | UpdateChannelPolicy_Input
|
||||
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetAdminInvoiceSwapQuotes_Output | GetAdminTransactionSwapQuotes_Output | GetAssetsAndLiabilities_Output | GetInviteLinkState_Output | GetSeed_Output | ListAdminInvoiceSwaps_Output | ListAdminTxSwaps_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | PayAdminInvoiceSwap_Output | PayAdminTransactionSwap_Output | RefundAdminInvoiceSwap_Output | UpdateChannelPolicy_Output
|
||||
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | BumpTx_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetAdminInvoiceSwapQuotes_Input | GetAdminTransactionSwapQuotes_Input | GetAssetsAndLiabilities_Input | GetInviteLinkState_Input | GetSeed_Input | ListAdminInvoiceSwaps_Input | ListAdminTxSwaps_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | PayAdminInvoiceSwap_Input | PayAdminTransactionSwap_Input | RefundAdminInvoiceSwap_Input | UpdateChannelPolicy_Input
|
||||
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | BumpTx_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetAdminInvoiceSwapQuotes_Output | GetAdminTransactionSwapQuotes_Output | GetAssetsAndLiabilities_Output | GetInviteLinkState_Output | GetSeed_Output | ListAdminInvoiceSwaps_Output | ListAdminTxSwaps_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | PayAdminInvoiceSwap_Output | PayAdminTransactionSwap_Output | RefundAdminInvoiceSwap_Output | UpdateChannelPolicy_Output
|
||||
export type AppContext = {
|
||||
app_id: string
|
||||
}
|
||||
|
|
@ -75,6 +75,9 @@ export type BanUser_Output = ResultError | ({ status: 'OK' } & BanUserResponse)
|
|||
export type BatchUser_Input = UserMethodInputs
|
||||
export type BatchUser_Output = UserMethodOutputs
|
||||
|
||||
export type BumpTx_Input = {rpcName:'BumpTx', req: BumpTx}
|
||||
export type BumpTx_Output = ResultError | { status: 'OK' }
|
||||
|
||||
export type CloseChannel_Input = {rpcName:'CloseChannel', req: CloseChannelRequest}
|
||||
export type CloseChannel_Output = ResultError | ({ status: 'OK' } & CloseChannelResponse)
|
||||
|
||||
|
|
@ -364,6 +367,7 @@ export type ServerMethods = {
|
|||
AuthorizeManage?: (req: AuthorizeManage_Input & {ctx: UserContext }) => Promise<ManageAuthorization>
|
||||
BanDebit?: (req: BanDebit_Input & {ctx: UserContext }) => Promise<void>
|
||||
BanUser?: (req: BanUser_Input & {ctx: AdminContext }) => Promise<BanUserResponse>
|
||||
BumpTx?: (req: BumpTx_Input & {ctx: AdminContext }) => Promise<void>
|
||||
CloseChannel?: (req: CloseChannel_Input & {ctx: AdminContext }) => Promise<CloseChannelResponse>
|
||||
CreateOneTimeInviteLink?: (req: CreateOneTimeInviteLink_Input & {ctx: AdminContext }) => Promise<CreateOneTimeInviteLinkResponse>
|
||||
DecodeInvoice?: (req: DecodeInvoice_Input & {ctx: UserContext }) => Promise<DecodeInvoiceResponse>
|
||||
|
|
@ -1209,6 +1213,34 @@ export const BeaconDataValidate = (o?: BeaconData, opts: BeaconDataOptions = {},
|
|||
return null
|
||||
}
|
||||
|
||||
export type BumpTx = {
|
||||
output_index: number
|
||||
sat_per_vbyte: number
|
||||
txid: string
|
||||
}
|
||||
export const BumpTxOptionalFields: [] = []
|
||||
export type BumpTxOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
output_index_CustomCheck?: (v: number) => boolean
|
||||
sat_per_vbyte_CustomCheck?: (v: number) => boolean
|
||||
txid_CustomCheck?: (v: string) => boolean
|
||||
}
|
||||
export const BumpTxValidate = (o?: BumpTx, opts: BumpTxOptions = {}, path: string = 'BumpTx::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.output_index !== 'number') return new Error(`${path}.output_index: is not a number`)
|
||||
if (opts.output_index_CustomCheck && !opts.output_index_CustomCheck(o.output_index)) return new Error(`${path}.output_index: custom check failed`)
|
||||
|
||||
if (typeof o.sat_per_vbyte !== 'number') return new Error(`${path}.sat_per_vbyte: is not a number`)
|
||||
if (opts.sat_per_vbyte_CustomCheck && !opts.sat_per_vbyte_CustomCheck(o.sat_per_vbyte)) return new Error(`${path}.sat_per_vbyte: custom check failed`)
|
||||
|
||||
if (typeof o.txid !== 'string') return new Error(`${path}.txid: is not a string`)
|
||||
if (opts.txid_CustomCheck && !opts.txid_CustomCheck(o.txid)) return new Error(`${path}.txid: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type BundleData = {
|
||||
available_chunks: number[]
|
||||
base_64_data: string[]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue