From decd404bc92576c97bc1f9cb4a0ebffc2c674752 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 6 May 2020 19:13:27 -0700 Subject: [PATCH] rpc: add WithdrawAccount RPC --- clmrpc/trader.pb.go | 288 ++++++++++++++++++++----------------- clmrpc/trader.pb.gw.go | 24 ++-- clmrpc/trader.proto | 35 +++-- clmrpc/trader.swagger.json | 70 +++++---- rpcserver.go | 103 ++++++++++--- 5 files changed, 330 insertions(+), 190 deletions(-) diff --git a/clmrpc/trader.pb.go b/clmrpc/trader.pb.go index 5080fba..660d79b 100644 --- a/clmrpc/trader.pb.go +++ b/clmrpc/trader.pb.go @@ -193,8 +193,8 @@ func (m *ListAccountsResponse) GetAccounts() []*Account { type Output struct { // The value, in satoshis, of the output. Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` - // The script of the output to send the value to. - Script []byte `protobuf:"bytes,2,opt,name=script,proto3" json:"script,omitempty"` + // The address corresponding to the output. + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -232,11 +232,11 @@ func (m *Output) GetValue() uint32 { return 0 } -func (m *Output) GetScript() []byte { +func (m *Output) GetAddress() string { if m != nil { - return m.Script + return m.Address } - return nil + return "" } type CloseAccountRequest struct { @@ -331,83 +331,115 @@ func (m *CloseAccountResponse) GetCloseTxid() []byte { return nil } -type ModifyAccountRequest struct { - AccountSubKeyHex string `protobuf:"bytes,1,opt,name=account_sub_key_hex,json=accountSubKeyHex,proto3" json:"account_sub_key_hex,omitempty"` - NewAccountBalance int64 `protobuf:"varint,2,opt,name=new_account_balance,json=newAccountBalance,proto3" json:"new_account_balance,omitempty"` +type WithdrawAccountRequest struct { + // + //The trader key associated with the account that funds will be withdrawed + //from. + TraderKey []byte `protobuf:"bytes,1,opt,name=trader_key,json=traderKey,proto3" json:"trader_key,omitempty"` + // The outputs we'll withdraw funds from the account into. + Outputs []*Output `protobuf:"bytes,2,rep,name=outputs,proto3" json:"outputs,omitempty"` + // + //The fee rate, in satoshis per vbyte, to use for the withdrawal transaction. + SatPerByte uint32 `protobuf:"varint,3,opt,name=sat_per_byte,json=satPerByte,proto3" json:"sat_per_byte,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ModifyAccountRequest) Reset() { *m = ModifyAccountRequest{} } -func (m *ModifyAccountRequest) String() string { return proto.CompactTextString(m) } -func (*ModifyAccountRequest) ProtoMessage() {} -func (*ModifyAccountRequest) Descriptor() ([]byte, []int) { +func (m *WithdrawAccountRequest) Reset() { *m = WithdrawAccountRequest{} } +func (m *WithdrawAccountRequest) String() string { return proto.CompactTextString(m) } +func (*WithdrawAccountRequest) ProtoMessage() {} +func (*WithdrawAccountRequest) Descriptor() ([]byte, []int) { return fileDescriptor_b8f61804588c75fe, []int{6} } -func (m *ModifyAccountRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ModifyAccountRequest.Unmarshal(m, b) +func (m *WithdrawAccountRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WithdrawAccountRequest.Unmarshal(m, b) } -func (m *ModifyAccountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ModifyAccountRequest.Marshal(b, m, deterministic) +func (m *WithdrawAccountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WithdrawAccountRequest.Marshal(b, m, deterministic) } -func (m *ModifyAccountRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ModifyAccountRequest.Merge(m, src) +func (m *WithdrawAccountRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_WithdrawAccountRequest.Merge(m, src) } -func (m *ModifyAccountRequest) XXX_Size() int { - return xxx_messageInfo_ModifyAccountRequest.Size(m) +func (m *WithdrawAccountRequest) XXX_Size() int { + return xxx_messageInfo_WithdrawAccountRequest.Size(m) } -func (m *ModifyAccountRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ModifyAccountRequest.DiscardUnknown(m) +func (m *WithdrawAccountRequest) XXX_DiscardUnknown() { + xxx_messageInfo_WithdrawAccountRequest.DiscardUnknown(m) } -var xxx_messageInfo_ModifyAccountRequest proto.InternalMessageInfo +var xxx_messageInfo_WithdrawAccountRequest proto.InternalMessageInfo -func (m *ModifyAccountRequest) GetAccountSubKeyHex() string { +func (m *WithdrawAccountRequest) GetTraderKey() []byte { if m != nil { - return m.AccountSubKeyHex + return m.TraderKey } - return "" + return nil } -func (m *ModifyAccountRequest) GetNewAccountBalance() int64 { +func (m *WithdrawAccountRequest) GetOutputs() []*Output { if m != nil { - return m.NewAccountBalance + return m.Outputs + } + return nil +} + +func (m *WithdrawAccountRequest) GetSatPerByte() uint32 { + if m != nil { + return m.SatPerByte } return 0 } -type ModifyAccountResponse struct { +type WithdrawAccountResponse struct { + // The state of the account after processing the withdrawal. + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + // The transaction used to withdraw funds from the account. + WithdrawTxid []byte `protobuf:"bytes,2,opt,name=withdraw_txid,json=withdrawTxid,proto3" json:"withdraw_txid,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ModifyAccountResponse) Reset() { *m = ModifyAccountResponse{} } -func (m *ModifyAccountResponse) String() string { return proto.CompactTextString(m) } -func (*ModifyAccountResponse) ProtoMessage() {} -func (*ModifyAccountResponse) Descriptor() ([]byte, []int) { +func (m *WithdrawAccountResponse) Reset() { *m = WithdrawAccountResponse{} } +func (m *WithdrawAccountResponse) String() string { return proto.CompactTextString(m) } +func (*WithdrawAccountResponse) ProtoMessage() {} +func (*WithdrawAccountResponse) Descriptor() ([]byte, []int) { return fileDescriptor_b8f61804588c75fe, []int{7} } -func (m *ModifyAccountResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ModifyAccountResponse.Unmarshal(m, b) +func (m *WithdrawAccountResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WithdrawAccountResponse.Unmarshal(m, b) } -func (m *ModifyAccountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ModifyAccountResponse.Marshal(b, m, deterministic) +func (m *WithdrawAccountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WithdrawAccountResponse.Marshal(b, m, deterministic) } -func (m *ModifyAccountResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ModifyAccountResponse.Merge(m, src) +func (m *WithdrawAccountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_WithdrawAccountResponse.Merge(m, src) } -func (m *ModifyAccountResponse) XXX_Size() int { - return xxx_messageInfo_ModifyAccountResponse.Size(m) +func (m *WithdrawAccountResponse) XXX_Size() int { + return xxx_messageInfo_WithdrawAccountResponse.Size(m) } -func (m *ModifyAccountResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ModifyAccountResponse.DiscardUnknown(m) +func (m *WithdrawAccountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_WithdrawAccountResponse.DiscardUnknown(m) } -var xxx_messageInfo_ModifyAccountResponse proto.InternalMessageInfo +var xxx_messageInfo_WithdrawAccountResponse proto.InternalMessageInfo + +func (m *WithdrawAccountResponse) GetAccount() *Account { + if m != nil { + return m.Account + } + return nil +} + +func (m *WithdrawAccountResponse) GetWithdrawTxid() []byte { + if m != nil { + return m.WithdrawTxid + } + return nil +} type Account struct { // @@ -1054,8 +1086,8 @@ func init() { proto.RegisterType((*Output)(nil), "clmrpc.Output") proto.RegisterType((*CloseAccountRequest)(nil), "clmrpc.CloseAccountRequest") proto.RegisterType((*CloseAccountResponse)(nil), "clmrpc.CloseAccountResponse") - proto.RegisterType((*ModifyAccountRequest)(nil), "clmrpc.ModifyAccountRequest") - proto.RegisterType((*ModifyAccountResponse)(nil), "clmrpc.ModifyAccountResponse") + proto.RegisterType((*WithdrawAccountRequest)(nil), "clmrpc.WithdrawAccountRequest") + proto.RegisterType((*WithdrawAccountResponse)(nil), "clmrpc.WithdrawAccountResponse") proto.RegisterType((*Account)(nil), "clmrpc.Account") proto.RegisterType((*SubmitOrderRequest)(nil), "clmrpc.SubmitOrderRequest") proto.RegisterType((*SubmitOrderResponse)(nil), "clmrpc.SubmitOrderResponse") @@ -1071,76 +1103,76 @@ func init() { func init() { proto.RegisterFile("trader.proto", fileDescriptor_b8f61804588c75fe) } var fileDescriptor_b8f61804588c75fe = []byte{ - // 1093 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0x5f, 0x4f, 0xe3, 0x46, - 0x10, 0x27, 0x84, 0x24, 0x30, 0x09, 0xd4, 0x4c, 0xc2, 0x35, 0x17, 0xfe, 0xca, 0xed, 0xb5, 0x28, - 0x5c, 0x49, 0x8f, 0xaa, 0xf7, 0xd0, 0x3e, 0xf1, 0x27, 0x2a, 0xe8, 0xae, 0x80, 0x0c, 0xbd, 0x56, - 0xea, 0x83, 0xeb, 0xd8, 0x1b, 0x58, 0xc5, 0xd8, 0xa9, 0xd7, 0xe6, 0x92, 0x22, 0x54, 0xa9, 0x52, - 0x3f, 0x41, 0x3f, 0x5a, 0xbf, 0xc2, 0x49, 0xfd, 0x1a, 0xd5, 0xae, 0xd7, 0xf6, 0x26, 0x31, 0x0f, - 0xf7, 0xe6, 0xfd, 0xcd, 0xec, 0xfc, 0x66, 0x66, 0xe7, 0x8f, 0xa1, 0x16, 0x06, 0x96, 0x43, 0x82, - 0xfd, 0x61, 0xe0, 0x87, 0x3e, 0x96, 0x6d, 0xf7, 0x2e, 0x18, 0xda, 0xad, 0x8d, 0x1b, 0xdf, 0xbf, - 0x71, 0x49, 0xc7, 0x1a, 0xd2, 0x8e, 0xe5, 0x79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6d, 0x01, - 0xd8, 0x1c, 0x37, 0xc3, 0x11, 0x75, 0x12, 0x86, 0x0c, 0xd1, 0x23, 0x68, 0xfc, 0xe8, 0x3b, 0xb4, - 0x3f, 0x9e, 0xf2, 0xec, 0x2b, 0xa8, 0x27, 0xb9, 0x66, 0x51, 0x8f, 0x3b, 0x63, 0xde, 0x92, 0x91, - 0x30, 0xb0, 0x64, 0x68, 0x52, 0x74, 0x15, 0xf5, 0xde, 0x90, 0xf1, 0x29, 0x19, 0xe1, 0x3e, 0xd4, - 0x3d, 0xf2, 0xde, 0x4c, 0xae, 0xf4, 0x2c, 0xd7, 0xf2, 0x6c, 0x22, 0x92, 0x50, 0x34, 0x56, 0x3d, - 0xf2, 0x5e, 0x9a, 0x3f, 0x8a, 0x05, 0xfa, 0xa7, 0xb0, 0x36, 0x45, 0x1b, 0xfb, 0xab, 0x7f, 0x28, - 0x40, 0x45, 0x62, 0xb8, 0x99, 0x93, 0x9d, 0xa5, 0x18, 0x79, 0x43, 0xc6, 0xf8, 0x12, 0x16, 0x79, - 0xf4, 0x3e, 0xf5, 0xe2, 0x6c, 0x57, 0x0f, 0x34, 0x25, 0x3b, 0x97, 0x1c, 0x37, 0x52, 0x8d, 0xec, - 0xbd, 0x8a, 0xea, 0x7b, 0xed, 0xc1, 0xaa, 0x28, 0x25, 0x51, 0xb4, 0xe6, 0x2d, 0xa1, 0x37, 0xb7, - 0x61, 0x73, 0x41, 0x68, 0x68, 0x99, 0xe0, 0x54, 0xe0, 0xd8, 0x86, 0x12, 0x0b, 0xad, 0x90, 0x34, - 0x4b, 0x3b, 0x85, 0xdd, 0x95, 0x83, 0xc6, 0x54, 0x99, 0x5c, 0x71, 0x99, 0x11, 0xab, 0x70, 0xdf, - 0x95, 0xbc, 0x97, 0x63, 0xdf, 0x05, 0x72, 0xcd, 0xd3, 0x6e, 0x01, 0x5e, 0x45, 0xbd, 0x3b, 0x1a, - 0x5e, 0x04, 0x0e, 0x09, 0x92, 0xa4, 0x6f, 0x43, 0xd1, 0x62, 0x03, 0x11, 0x69, 0xf5, 0xa0, 0x9a, - 0x9a, 0x67, 0x83, 0xd3, 0x39, 0x83, 0x4b, 0xb8, 0x42, 0x8f, 0x3a, 0x32, 0xda, 0x54, 0xe1, 0x88, - 0x3a, 0x5c, 0xa1, 0x47, 0x9d, 0xa3, 0x25, 0xa8, 0x38, 0x24, 0xb4, 0xa8, 0xcb, 0xf4, 0x07, 0xa8, - 0x4f, 0x50, 0xc8, 0x82, 0xf8, 0x1e, 0x96, 0xa9, 0x77, 0x6f, 0xb9, 0xd4, 0x31, 0x7d, 0x2e, 0x90, - 0x6c, 0x69, 0x30, 0x67, 0xb1, 0x50, 0x5c, 0x3a, 0x9d, 0x33, 0x6a, 0x54, 0x39, 0xe3, 0x86, 0xe8, - 0x15, 0x32, 0x0c, 0x49, 0xec, 0xc4, 0xe2, 0xe9, 0x9c, 0x91, 0x22, 0x2a, 0x79, 0x1d, 0x56, 0x79, - 0xb3, 0x89, 0x5b, 0x69, 0x07, 0xbe, 0x03, 0x54, 0x41, 0xe9, 0xd0, 0x36, 0x2c, 0x58, 0x6c, 0x90, - 0xf4, 0x9e, 0x1a, 0xb5, 0x21, 0x04, 0x5c, 0xa1, 0x47, 0x9d, 0xa4, 0x03, 0xd4, 0xa8, 0x0d, 0x21, - 0xd0, 0xbf, 0x05, 0x3c, 0xe6, 0x55, 0xe5, 0x4e, 0x25, 0xb3, 0x2a, 0x02, 0x34, 0x3d, 0x9f, 0x97, - 0xa2, 0x2c, 0x7d, 0x01, 0x9d, 0x73, 0x84, 0xcf, 0x89, 0x89, 0x6b, 0xb2, 0x02, 0xff, 0x9e, 0x87, - 0x52, 0x1c, 0xad, 0x0e, 0xb5, 0x88, 0x91, 0x20, 0x69, 0x00, 0x69, 0x62, 0x02, 0xe3, 0xfd, 0x15, - 0x58, 0x21, 0x31, 0xfb, 0x74, 0x24, 0x73, 0x52, 0x34, 0x14, 0x04, 0x35, 0x28, 0x5a, 0x77, 0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 0x7b, 0xa2, 0x15, 0x55, 0xd5, 0xe3, 0xb7, 0x17, 0x57, 0xdd, - 0x13, 0x6d, 0x01, 0x01, 0xca, 0xf2, 0xbb, 0x74, 0xf0, 0x5f, 0x09, 0xca, 0xd7, 0x62, 0xa2, 0xe1, - 0xcf, 0x50, 0x55, 0x16, 0x23, 0xb6, 0xb2, 0x86, 0x9c, 0xde, 0x96, 0xad, 0xe9, 0x05, 0xa5, 0xaf, - 0xff, 0xf5, 0xef, 0x87, 0x7f, 0xe6, 0xd7, 0x74, 0xad, 0x73, 0xff, 0xaa, 0x63, 0xbb, 0x77, 0x9d, - 0x64, 0x61, 0x7d, 0x57, 0x68, 0xa3, 0x0d, 0x35, 0x75, 0xf1, 0xe1, 0x7a, 0x72, 0x3b, 0x67, 0x4b, - 0xb6, 0x36, 0xf2, 0x85, 0xb2, 0x37, 0x9a, 0x82, 0x07, 0x71, 0x86, 0x07, 0x87, 0x50, 0x53, 0xf7, - 0x4f, 0x46, 0x92, 0xb3, 0xf6, 0x32, 0x92, 0xbc, 0x95, 0xa5, 0xbf, 0x10, 0x24, 0xdb, 0xed, 0xcd, - 0x69, 0x92, 0xce, 0x43, 0xb6, 0x0e, 0x1e, 0xf1, 0x4f, 0x58, 0x9e, 0x58, 0x21, 0x98, 0x5a, 0xcd, - 0x5b, 0x68, 0xad, 0xcd, 0x27, 0xa4, 0x92, 0xf4, 0x95, 0x20, 0xdd, 0xd3, 0xbf, 0x98, 0x25, 0xcd, - 0xd9, 0x83, 0x8f, 0x3c, 0xaf, 0x16, 0x54, 0x95, 0x01, 0x9b, 0x3d, 0xd8, 0xec, 0x60, 0x6f, 0xad, - 0xe7, 0xca, 0x24, 0xf5, 0x73, 0x41, 0x5d, 0xd7, 0x57, 0x12, 0x6a, 0xd1, 0xdf, 0xe2, 0xe9, 0x7e, - 0x05, 0xc8, 0x26, 0x26, 0x3e, 0x57, 0xdf, 0x66, 0x62, 0xb4, 0xb6, 0x5a, 0x79, 0x22, 0x69, 0xff, - 0x99, 0xb0, 0xaf, 0xe1, 0x94, 0x7d, 0x74, 0xa1, 0xaa, 0xcc, 0xbf, 0xcc, 0xff, 0xd9, 0x59, 0x9a, - 0xf9, 0x9f, 0x37, 0x30, 0x3f, 0x17, 0xf6, 0xb7, 0xda, 0x1b, 0x93, 0xf6, 0x3b, 0x0f, 0xca, 0x9c, - 0x7a, 0xec, 0x95, 0xc5, 0xef, 0xdf, 0x37, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x4b, 0x30, 0xef, - 0x38, 0x46, 0x0a, 0x00, 0x00, + // 1098 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0xdd, 0x4e, 0x1b, 0x47, + 0x14, 0xc6, 0x18, 0xdb, 0x70, 0xbc, 0x90, 0x65, 0x4c, 0x52, 0xc7, 0x10, 0x40, 0xdb, 0xa6, 0xa5, + 0x26, 0xc2, 0x0d, 0x55, 0xab, 0xaa, 0xbd, 0xe2, 0xc7, 0x2a, 0xa8, 0x11, 0x58, 0x0b, 0x4d, 0x2a, + 0xf5, 0x62, 0x3b, 0xde, 0x1d, 0x60, 0xe4, 0x65, 0xd7, 0xdd, 0x99, 0x25, 0x50, 0x94, 0x9b, 0x56, + 0x79, 0x82, 0x3e, 0x5a, 0x5f, 0x21, 0xd7, 0x7d, 0x86, 0x6a, 0x66, 0x67, 0xbc, 0x63, 0x7b, 0x51, + 0x95, 0x3b, 0xef, 0x77, 0xce, 0x9c, 0xef, 0x3b, 0x33, 0xe7, 0xc7, 0x60, 0xf1, 0x04, 0x07, 0x24, + 0xd9, 0x19, 0x26, 0x31, 0x8f, 0x51, 0xd5, 0x0f, 0xaf, 0x93, 0xa1, 0xdf, 0x5a, 0xbb, 0x8c, 0xe3, + 0xcb, 0x90, 0x74, 0xf0, 0x90, 0x76, 0x70, 0x14, 0xc5, 0x1c, 0x73, 0x1a, 0x47, 0x2c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0x2d, 0x0d, 0x34, 0x43, 0x8e, 0x38, 0x7f, 0x95, 0xe0, 0xc9, 0x1b, 0xca, 0xaf, + 0x82, 0x04, 0xbf, 0x9d, 0x10, 0xf7, 0xac, 0x40, 0xdc, 0x42, 0x86, 0xfc, 0xf4, 0x31, 0xda, 0xd0, + 0x26, 0x58, 0x0c, 0x73, 0x6f, 0x48, 0x12, 0xaf, 0x7f, 0xc7, 0x49, 0xb3, 0x2c, 0xef, 0x0c, 0x18, + 0xe6, 0x3d, 0x92, 0xec, 0xdf, 0x71, 0xe2, 0x50, 0xf8, 0x64, 0x4a, 0x84, 0x4a, 0xe0, 0x4b, 0xa8, + 0xa9, 0xfb, 0x97, 0x12, 0x0a, 0xde, 0x47, 0xdb, 0x45, 0x19, 0xbd, 0x55, 0x51, 0xb2, 0x74, 0x67, + 0xa5, 0x66, 0x4b, 0x83, 0xe7, 0x22, 0xe1, 0x0f, 0x25, 0xa8, 0xa9, 0x93, 0xff, 0x97, 0xe1, 0x0b, + 0x98, 0x17, 0x29, 0xc4, 0x34, 0xe2, 0x32, 0x54, 0x7d, 0xd7, 0x36, 0x52, 0xec, 0x09, 0xdc, 0x1d, + 0x79, 0xe4, 0x25, 0x51, 0x36, 0x4b, 0x62, 0x1b, 0x96, 0x65, 0xb5, 0xca, 0xbe, 0xf0, 0xae, 0x08, + 0xbd, 0xbc, 0xe2, 0xcd, 0x39, 0xe9, 0x61, 0xe7, 0x86, 0x23, 0x89, 0xa3, 0x36, 0x54, 0x18, 0xc7, + 0x9c, 0x34, 0x2b, 0x9b, 0xa5, 0xad, 0xa5, 0xdd, 0x95, 0x89, 0x4c, 0xcf, 0x84, 0xcd, 0xcd, 0x5c, + 0x84, 0x76, 0xe3, 0x61, 0xab, 0x99, 0x76, 0x89, 0xc8, 0x34, 0x31, 0xa0, 0xb3, 0xb4, 0x7f, 0x4d, + 0xf9, 0x69, 0x12, 0x90, 0x44, 0x3f, 0xe9, 0x06, 0x94, 0x31, 0x1b, 0xa8, 0x8b, 0xac, 0x8f, 0xc2, + 0xb3, 0xc1, 0xd1, 0x8c, 0x2b, 0x2c, 0xc2, 0xa1, 0xaf, 0x2e, 0xce, 0x70, 0xd8, 0xa7, 0x81, 0x70, + 0xe8, 0xd3, 0x60, 0x7f, 0x01, 0x6a, 0x01, 0xe1, 0x98, 0x86, 0xcc, 0xb9, 0x87, 0xc6, 0x18, 0x85, + 0x7a, 0xb0, 0x1f, 0x60, 0x91, 0x46, 0x37, 0x38, 0xa4, 0x81, 0x17, 0x0b, 0x83, 0x62, 0x1b, 0x25, + 0x73, 0x9c, 0x19, 0xe5, 0xa1, 0xa3, 0x19, 0xd7, 0xa2, 0xc6, 0x37, 0x5a, 0x93, 0xed, 0x48, 0x86, + 0x9c, 0x64, 0x22, 0xe6, 0x8f, 0x66, 0xdc, 0x11, 0x62, 0x92, 0x37, 0x60, 0x59, 0xf4, 0xb3, 0x3c, + 0x35, 0x6a, 0xf2, 0xd7, 0x80, 0x4c, 0x50, 0x09, 0xda, 0x80, 0x39, 0xcc, 0x06, 0xba, 0xbd, 0xcd, + 0xac, 0x5d, 0x69, 0x10, 0x0e, 0x7d, 0x1a, 0xe8, 0x32, 0x36, 0xb3, 0x76, 0xa5, 0xc1, 0xf9, 0x06, + 0xd0, 0x01, 0x8e, 0x7c, 0x12, 0x4e, 0x5c, 0x66, 0x5d, 0x26, 0xe8, 0x45, 0x71, 0xe4, 0x13, 0xdd, + 0x5b, 0x12, 0x3a, 0x11, 0x88, 0x18, 0x45, 0x63, 0xc7, 0x32, 0x3d, 0xce, 0xfb, 0x59, 0xa8, 0x64, + 0xd9, 0x3a, 0x60, 0xa5, 0x8c, 0x24, 0x1e, 0x4b, 0xfb, 0x46, 0x05, 0x8e, 0x61, 0xa2, 0x81, 0x13, + 0xcc, 0x89, 0x77, 0x41, 0x6f, 0xd5, 0x9d, 0x94, 0x5d, 0x03, 0x41, 0x36, 0x94, 0xf1, 0x35, 0x97, + 0x45, 0x57, 0x76, 0xc5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b6, 0xd5, + 0x2a, 0x32, 0xa9, 0xf8, 0x4f, 0x64, 0x7c, 0x1b, 0x4d, 0xc4, 0x47, 0x21, 0xd4, 0x8d, 0x31, 0x98, + 0xeb, 0x9f, 0x1e, 0xa9, 0xb9, 0xfe, 0xa2, 0xb9, 0xf9, 0x99, 0x8c, 0xbf, 0xde, 0x5e, 0x1b, 0x8f, + 0xdf, 0xb9, 0x37, 0xc6, 0xd5, 0xbb, 0x7e, 0x55, 0xfe, 0xd1, 0xfc, 0xfa, 0xbf, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x61, 0xde, 0x83, 0x3e, 0xb0, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1158,7 +1190,7 @@ type TraderClient interface { InitAccount(ctx context.Context, in *InitAccountRequest, opts ...grpc.CallOption) (*Account, error) ListAccounts(ctx context.Context, in *ListAccountsRequest, opts ...grpc.CallOption) (*ListAccountsResponse, error) CloseAccount(ctx context.Context, in *CloseAccountRequest, opts ...grpc.CallOption) (*CloseAccountResponse, error) - ModifyAccount(ctx context.Context, in *ModifyAccountRequest, opts ...grpc.CallOption) (*ModifyAccountResponse, error) + WithdrawAccount(ctx context.Context, in *WithdrawAccountRequest, opts ...grpc.CallOption) (*WithdrawAccountResponse, error) SubmitOrder(ctx context.Context, in *SubmitOrderRequest, opts ...grpc.CallOption) (*SubmitOrderResponse, error) ListOrders(ctx context.Context, in *ListOrdersRequest, opts ...grpc.CallOption) (*ListOrdersResponse, error) CancelOrder(ctx context.Context, in *CancelOrderRequest, opts ...grpc.CallOption) (*CancelOrderResponse, error) @@ -1199,9 +1231,9 @@ func (c *traderClient) CloseAccount(ctx context.Context, in *CloseAccountRequest return out, nil } -func (c *traderClient) ModifyAccount(ctx context.Context, in *ModifyAccountRequest, opts ...grpc.CallOption) (*ModifyAccountResponse, error) { - out := new(ModifyAccountResponse) - err := c.cc.Invoke(ctx, "/clmrpc.Trader/ModifyAccount", in, out, opts...) +func (c *traderClient) WithdrawAccount(ctx context.Context, in *WithdrawAccountRequest, opts ...grpc.CallOption) (*WithdrawAccountResponse, error) { + out := new(WithdrawAccountResponse) + err := c.cc.Invoke(ctx, "/clmrpc.Trader/WithdrawAccount", in, out, opts...) if err != nil { return nil, err } @@ -1240,7 +1272,7 @@ type TraderServer interface { InitAccount(context.Context, *InitAccountRequest) (*Account, error) ListAccounts(context.Context, *ListAccountsRequest) (*ListAccountsResponse, error) CloseAccount(context.Context, *CloseAccountRequest) (*CloseAccountResponse, error) - ModifyAccount(context.Context, *ModifyAccountRequest) (*ModifyAccountResponse, error) + WithdrawAccount(context.Context, *WithdrawAccountRequest) (*WithdrawAccountResponse, error) SubmitOrder(context.Context, *SubmitOrderRequest) (*SubmitOrderResponse, error) ListOrders(context.Context, *ListOrdersRequest) (*ListOrdersResponse, error) CancelOrder(context.Context, *CancelOrderRequest) (*CancelOrderResponse, error) @@ -1304,20 +1336,20 @@ func _Trader_CloseAccount_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } -func _Trader_ModifyAccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ModifyAccountRequest) +func _Trader_WithdrawAccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WithdrawAccountRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(TraderServer).ModifyAccount(ctx, in) + return srv.(TraderServer).WithdrawAccount(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/clmrpc.Trader/ModifyAccount", + FullMethod: "/clmrpc.Trader/WithdrawAccount", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(TraderServer).ModifyAccount(ctx, req.(*ModifyAccountRequest)) + return srv.(TraderServer).WithdrawAccount(ctx, req.(*WithdrawAccountRequest)) } return interceptor(ctx, in, info, handler) } @@ -1393,8 +1425,8 @@ var _Trader_serviceDesc = grpc.ServiceDesc{ Handler: _Trader_CloseAccount_Handler, }, { - MethodName: "ModifyAccount", - Handler: _Trader_ModifyAccount_Handler, + MethodName: "WithdrawAccount", + Handler: _Trader_WithdrawAccount_Handler, }, { MethodName: "SubmitOrder", diff --git a/clmrpc/trader.pb.gw.go b/clmrpc/trader.pb.gw.go index d06679c..cba793d 100644 --- a/clmrpc/trader.pb.gw.go +++ b/clmrpc/trader.pb.gw.go @@ -89,8 +89,8 @@ func request_Trader_CloseAccount_0(ctx context.Context, marshaler runtime.Marsha } -func request_Trader_ModifyAccount_0(ctx context.Context, marshaler runtime.Marshaler, client TraderClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq ModifyAccountRequest +func request_Trader_WithdrawAccount_0(ctx context.Context, marshaler runtime.Marshaler, client TraderClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq WithdrawAccountRequest var metadata runtime.ServerMetadata newReader, berr := utilities.IOReaderFactory(req.Body) @@ -108,18 +108,18 @@ func request_Trader_ModifyAccount_0(ctx context.Context, marshaler runtime.Marsh _ = err ) - val, ok = pathParams["account_sub_key_hex"] + val, ok = pathParams["trader_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "account_sub_key_hex") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "trader_key") } - protoReq.AccountSubKeyHex, err = runtime.String(val) + protoReq.TraderKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "account_sub_key_hex", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "trader_key", err) } - msg, err := client.ModifyAccount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.WithdrawAccount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } @@ -275,7 +275,7 @@ func RegisterTraderHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli }) - mux.Handle("POST", pattern_Trader_ModifyAccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_Trader_WithdrawAccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -284,14 +284,14 @@ func RegisterTraderHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Trader_ModifyAccount_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Trader_WithdrawAccount_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Trader_ModifyAccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Trader_WithdrawAccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -365,7 +365,7 @@ var ( pattern_Trader_CloseAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "clm", "accounts", "trader_key"}, "")) - pattern_Trader_ModifyAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "clm", "accounts", "account_sub_key_hex"}, "")) + pattern_Trader_WithdrawAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "clm", "accounts", "withdraw", "trader_key"}, "")) pattern_Trader_SubmitOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "clm", "orders"}, "")) @@ -381,7 +381,7 @@ var ( forward_Trader_CloseAccount_0 = runtime.ForwardResponseMessage - forward_Trader_ModifyAccount_0 = runtime.ForwardResponseMessage + forward_Trader_WithdrawAccount_0 = runtime.ForwardResponseMessage forward_Trader_SubmitOrder_0 = runtime.ForwardResponseMessage diff --git a/clmrpc/trader.proto b/clmrpc/trader.proto index 0744aa3..f2ddfc1 100644 --- a/clmrpc/trader.proto +++ b/clmrpc/trader.proto @@ -25,9 +25,9 @@ service Trader { }; }; - rpc ModifyAccount (ModifyAccountRequest) returns (ModifyAccountResponse) { + rpc WithdrawAccount (WithdrawAccountRequest) returns (WithdrawAccountResponse) { option (google.api.http) = { - post: "/v1/clm/accounts/{account_sub_key_hex}" + post: "/v1/clm/accounts/withdraw/{trader_key}" body: "*" }; }; @@ -67,8 +67,8 @@ message Output { // The value, in satoshis, of the output. uint32 value = 1; - // The script of the output to send the value to. - bytes script = 2; + // The address corresponding to the output. + string address = 2; } message CloseAccountRequest { @@ -87,13 +87,28 @@ message CloseAccountResponse { bytes close_txid = 1 [json_name = "close_txid"]; } -message ModifyAccountRequest { - string account_sub_key_hex = 1; - int64 new_account_balance = 2; -} -message ModifyAccountResponse { -} +message WithdrawAccountRequest { + /* + The trader key associated with the account that funds will be withdrawed + from. + */ + bytes trader_key = 1; + // The outputs we'll withdraw funds from the account into. + repeated Output outputs = 2; + + /* + The fee rate, in satoshis per vbyte, to use for the withdrawal transaction. + */ + uint32 sat_per_byte = 3; +} +message WithdrawAccountResponse { + // The state of the account after processing the withdrawal. + Account account = 1; + + // The transaction used to withdraw funds from the account. + bytes withdraw_txid = 2; +} enum AccountState { // The state of an account when it is pending its confirmation on-chain. diff --git a/clmrpc/trader.swagger.json b/clmrpc/trader.swagger.json index 2814fe7..9462e95 100644 --- a/clmrpc/trader.swagger.json +++ b/clmrpc/trader.swagger.json @@ -55,30 +55,32 @@ ] } }, - "/v1/clm/accounts/{account_sub_key_hex}": { + "/v1/clm/accounts/withdraw/{trader_key}": { "post": { - "operationId": "ModifyAccount", + "operationId": "WithdrawAccount", "responses": { "200": { "description": "A successful response.", "schema": { - "$ref": "#/definitions/clmrpcModifyAccountResponse" + "$ref": "#/definitions/clmrpcWithdrawAccountResponse" } } }, "parameters": [ { - "name": "account_sub_key_hex", + "name": "trader_key", + "description": "The trader key associated with the account that funds will be withdrawed\nfrom.", "in": "path", "required": true, - "type": "string" + "type": "string", + "format": "byte" }, { "name": "body", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/clmrpcModifyAccountRequest" + "$ref": "#/definitions/clmrpcWithdrawAccountRequest" } } ], @@ -340,21 +342,6 @@ } } }, - "clmrpcModifyAccountRequest": { - "type": "object", - "properties": { - "account_sub_key_hex": { - "type": "string" - }, - "new_account_balance": { - "type": "string", - "format": "int64" - } - } - }, - "clmrpcModifyAccountResponse": { - "type": "object" - }, "clmrpcOrder": { "type": "object", "properties": { @@ -422,10 +409,9 @@ "format": "int64", "description": "The value, in satoshis, of the output." }, - "script": { + "address": { "type": "string", - "format": "byte", - "description": "The script of the output to send the value to." + "description": "The address corresponding to the output." } } }, @@ -453,6 +439,42 @@ "description": "*\nOrder was accepted." } } + }, + "clmrpcWithdrawAccountRequest": { + "type": "object", + "properties": { + "trader_key": { + "type": "string", + "format": "byte", + "description": "The trader key associated with the account that funds will be withdrawed\nfrom." + }, + "outputs": { + "type": "array", + "items": { + "$ref": "#/definitions/clmrpcOutput" + }, + "description": "The outputs we'll withdraw funds from the account into." + }, + "sat_per_byte": { + "type": "integer", + "format": "int64", + "description": "The fee rate, in satoshis per vbyte, to use for the withdrawal transaction." + } + } + }, + "clmrpcWithdrawAccountResponse": { + "type": "object", + "properties": { + "account": { + "$ref": "#/definitions/clmrpcAccount", + "description": "The state of the account after processing the withdrawal." + }, + "withdraw_txid": { + "type": "string", + "format": "byte", + "description": "The transaction used to withdraw funds from the account." + } + } } } } diff --git a/rpcserver.go b/rpcserver.go index 9c4f4d9..6e2d40c 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -24,6 +24,7 @@ import ( "github.com/lightninglabs/loop/lndclient" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lnrpc" + "github.com/lightningnetwork/lnd/lnwallet/chainfee" "golang.org/x/sync/errgroup" ) @@ -722,6 +723,59 @@ func marshallAccount(a *account.Account) (*clmrpc.Account, error) { }, nil } +// WithdrawAccount handles a trader's request to withdraw funds from the +// specified account by spending the current account output to the specified +// outputs. +func (s *rpcServer) WithdrawAccount(ctx context.Context, + req *clmrpc.WithdrawAccountRequest) (*clmrpc.WithdrawAccountResponse, error) { + + // Ensure the trader key is well formed. + traderKey, err := btcec.ParsePubKey(req.TraderKey, btcec.S256()) + if err != nil { + return nil, err + } + + // Ensure the outputs we'll withdraw to are well formed. + if len(req.Outputs) == 0 { + return nil, errors.New("missing outputs for withdrawal") + } + outputs, err := s.parseRPCOutputs(req.Outputs) + if err != nil { + return nil, err + } + + // Enforce a minimum fee rate of 1 sat/vbyte. + feeRate := chainfee.SatPerKVByte(req.SatPerByte * 1000).FeePerKWeight() + if feeRate < chainfee.FeePerKwFloor { + log.Infof("Manual fee rate input of %d sat/kw is too low, "+ + "using %d sat/kw instead", feeRate, + chainfee.FeePerKwFloor) + feeRate = chainfee.FeePerKwFloor + } + + // Proceed to process the withdrawal and map its response to the RPC's + // response. + modifiedAccount, tx, err := s.accountManager.WithdrawAccount( + ctx, traderKey, outputs, feeRate, + atomic.LoadUint32(&s.bestHeight), + ) + if err != nil { + return nil, err + } + + rpcModifiedAccount, err := marshallAccount(modifiedAccount) + if err != nil { + return nil, err + } + txHash := tx.TxHash() + + return &clmrpc.WithdrawAccountResponse{ + Account: rpcModifiedAccount, + WithdrawTxid: txHash[:], + }, nil +} + +// CloseAccount handles a trader's request to close the specified account. func (s *rpcServer) CloseAccount(ctx context.Context, req *clmrpc.CloseAccountRequest) (*clmrpc.CloseAccountResponse, error) { @@ -732,18 +786,9 @@ func (s *rpcServer) CloseAccount(ctx context.Context, var closeOutputs []*wire.TxOut if len(req.Outputs) > 0 { - closeOutputs = make([]*wire.TxOut, 0, len(req.Outputs)) - for _, output := range req.Outputs { - // Make sure they've provided a valid output script. - _, err := txscript.ParsePkScript(output.Script) - if err != nil { - return nil, err - } - - closeOutputs = append(closeOutputs, &wire.TxOut{ - Value: int64(output.Value), - PkScript: output.Script, - }) + closeOutputs, err = s.parseRPCOutputs(req.Outputs) + if err != nil { + return nil, err } } @@ -760,11 +805,37 @@ func (s *rpcServer) CloseAccount(ctx context.Context, }, nil } -func (s *rpcServer) ModifyAccount(ctx context.Context, - req *clmrpc.ModifyAccountRequest) ( - *clmrpc.ModifyAccountResponse, error) { +// parseRPCOutputs maps []*clmrpc.Output -> []*wire.TxOut. +func (s *rpcServer) parseRPCOutputs(outputs []*clmrpc.Output) ([]*wire.TxOut, + error) { - return nil, fmt.Errorf("unimplemented") + res := make([]*wire.TxOut, 0, len(outputs)) + for _, output := range outputs { + // Decode each address, make sure it's valid for the current + // network, and derive its output script. + addr, err := btcutil.DecodeAddress( + output.Address, s.lndServices.ChainParams, + ) + if err != nil { + return nil, err + } + if !addr.IsForNet(s.lndServices.ChainParams) { + return nil, fmt.Errorf("invalid address %v for %v "+ + "network", addr.String(), + s.lndServices.ChainParams.Name) + } + outputScript, err := txscript.PayToAddrScript(addr) + if err != nil { + return nil, err + } + + res = append(res, &wire.TxOut{ + Value: int64(output.Value), + PkScript: outputScript, + }) + } + + return res, nil } // SubmitOrder assembles all the information that is required to submit an order