admin channels

This commit is contained in:
boufni95 2024-11-06 19:55:10 +00:00
parent 03d4bfc28f
commit 70dc928f1b
16 changed files with 590 additions and 109 deletions

View file

@ -58,12 +58,14 @@ type Client struct {
AddAppInvoice func(req AddAppInvoiceRequest) (*NewInvoiceResponse, error)
AddAppUser func(req AddAppUserRequest) (*AppUser, error)
AddAppUserInvoice func(req AddAppUserInvoiceRequest) (*NewInvoiceResponse, error)
AddPeer func(req AddPeerRequest) error
AddProduct func(req AddProductRequest) (*Product, error)
AuthApp func(req AuthAppRequest) (*AuthApp, error)
AuthorizeDebit func(req DebitAuthorizationRequest) (*DebitAuthorization, error)
BanDebit func(req DebitOperation) error
BanUser func(req BanUserRequest) (*BanUserResponse, error)
// batching method: BatchUser not implemented
CloseChannel func(req CloseChannelRequest) (*CloseChannelResponse, error)
CreateOneTimeInviteLink func(req CreateOneTimeInviteLinkRequest) (*CreateOneTimeInviteLinkResponse, error)
DecodeInvoice func(req DecodeInvoiceRequest) (*DecodeInvoiceResponse, error)
EditDebit func(req DebitAuthorizationRequest) error
@ -237,6 +239,30 @@ func NewClient(params ClientParams) *Client {
}
return &res, nil
},
AddPeer: func(req AddPeerRequest) error {
auth, err := params.RetrieveAdminAuth()
if err != nil {
return err
}
finalRoute := "/api/admin/peer"
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
},
AddProduct: func(req AddProductRequest) (*Product, error) {
auth, err := params.RetrieveUserAuth()
if err != nil {
@ -378,6 +404,35 @@ func NewClient(params ClientParams) *Client {
return &res, nil
},
// batching method: BatchUser not implemented
CloseChannel: func(req CloseChannelRequest) (*CloseChannelResponse, error) {
auth, err := params.RetrieveAdminAuth()
if err != nil {
return nil, err
}
finalRoute := "/api/admin/channel/close"
body, err := json.Marshal(req)
if err != nil {
return nil, err
}
resBody, err := doPostRequest(params.BaseURL+finalRoute, body, auth)
if err != nil {
return nil, err
}
result := ResultError{}
err = json.Unmarshal(resBody, &result)
if err != nil {
return nil, err
}
if result.Status == "ERROR" {
return nil, fmt.Errorf(result.Reason)
}
res := CloseChannelResponse{}
err = json.Unmarshal(resBody, &res)
if err != nil {
return nil, err
}
return &res, nil
},
CreateOneTimeInviteLink: func(req CreateOneTimeInviteLinkRequest) (*CreateOneTimeInviteLinkResponse, error) {
auth, err := params.RetrieveAdminAuth()
if err != nil {
@ -1267,11 +1322,11 @@ func NewClient(params ClientParams) *Client {
return &res, nil
},
OpenChannel: func(req OpenChannelRequest) (*OpenChannelResponse, error) {
auth, err := params.RetrieveUserAuth()
auth, err := params.RetrieveAdminAuth()
if err != nil {
return nil, err
}
finalRoute := "/api/user/open/channel"
finalRoute := "/api/admin/channel/open"
body, err := json.Marshal(req)
if err != nil {
return nil, err

View file

@ -95,6 +95,11 @@ type AddAppUserRequest struct {
Fail_if_exists bool `json:"fail_if_exists"`
Identifier string `json:"identifier"`
}
type AddPeerRequest struct {
Host string `json:"host"`
Port int64 `json:"port"`
Pubkey string `json:"pubkey"`
}
type AddProductRequest struct {
Name string `json:"name"`
Price_sats int64 `json:"price_sats"`
@ -153,6 +158,15 @@ type BannedAppUser struct {
type CallbackUrl struct {
Url string `json:"url"`
}
type CloseChannelRequest struct {
Force bool `json:"force"`
Funding_txid string `json:"funding_txid"`
Output_index int64 `json:"output_index"`
Sat_per_v_byte int64 `json:"sat_per_v_byte"`
}
type CloseChannelResponse struct {
Closing_txid string `json:"closing_txid"`
}
type ClosedChannel struct {
Capacity int64 `json:"capacity"`
Channel_id string `json:"channel_id"`
@ -222,6 +236,9 @@ type GetAppUserLNURLInfoRequest struct {
type GetAppUserRequest struct {
User_identifier string `json:"user_identifier"`
}
type GetChannelPolicyRequest struct {
Channel_id string `json:"channel_id"`
}
type GetInviteTokenStateRequest struct {
Invite_token string `json:"invite_token"`
}
@ -363,13 +380,14 @@ type OpenChannel struct {
Remote_balance int64 `json:"remote_balance"`
}
type OpenChannelRequest struct {
Closeaddress string `json:"closeAddress"`
Destination string `json:"destination"`
Fundingamount int64 `json:"fundingAmount"`
Pushamount int64 `json:"pushAmount"`
Close_address string `json:"close_address"`
Local_funding_amount int64 `json:"local_funding_amount"`
Node_pubkey string `json:"node_pubkey"`
Push_sat int64 `json:"push_sat"`
Sat_per_v_byte int64 `json:"sat_per_v_byte"`
}
type OpenChannelResponse struct {
Channelid string `json:"channelId"`
Channel_id string `json:"channel_id"`
}
type PayAddressRequest struct {
Address string `json:"address"`