From bba8770bb47fb838d417b901385d87438c12a2b7 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 24 Apr 2016 20:26:32 -0700 Subject: [PATCH] lnrpc: add address type param to NewAddress MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new available address types are: regular p2pkh, p2wkh, and finally p2wkh nested within p2sh. The latter address type will initially be used to allow users to “fund” the lnd wallet. --- lnrpc/rpc.pb.go | 72 +++++++++++++++++++++++++++++++++++-------------- lnrpc/rpc.proto | 9 ++++++- rpcserver.go | 25 ++++++++++++++--- 3 files changed, 81 insertions(+), 25 deletions(-) diff --git a/lnrpc/rpc.pb.go b/lnrpc/rpc.pb.go index 36cf6343..7303f3ca 100644 --- a/lnrpc/rpc.pb.go +++ b/lnrpc/rpc.pb.go @@ -36,6 +36,32 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. const _ = proto.ProtoPackageIsVersion1 +type NewAddressRequest_AddressType int32 + +const ( + NewAddressRequest_WITNESS_PUBKEY_HASH NewAddressRequest_AddressType = 0 + NewAddressRequest_NESTED_PUBKEY_HASH NewAddressRequest_AddressType = 1 + NewAddressRequest_PUBKEY_HASH NewAddressRequest_AddressType = 2 +) + +var NewAddressRequest_AddressType_name = map[int32]string{ + 0: "WITNESS_PUBKEY_HASH", + 1: "NESTED_PUBKEY_HASH", + 2: "PUBKEY_HASH", +} +var NewAddressRequest_AddressType_value = map[string]int32{ + "WITNESS_PUBKEY_HASH": 0, + "NESTED_PUBKEY_HASH": 1, + "PUBKEY_HASH": 2, +} + +func (x NewAddressRequest_AddressType) String() string { + return proto.EnumName(NewAddressRequest_AddressType_name, int32(x)) +} +func (NewAddressRequest_AddressType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor0, []int{2, 0} +} + type SendManyRequest struct { AddrToAmount map[string]int64 `protobuf:"bytes,1,rep,name=AddrToAmount" json:"AddrToAmount,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` } @@ -62,6 +88,7 @@ func (*SendManyResponse) ProtoMessage() {} func (*SendManyResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } type NewAddressRequest struct { + Type NewAddressRequest_AddressType `protobuf:"varint,1,opt,name=type,enum=lnrpc.NewAddressRequest_AddressType" json:"type,omitempty"` } func (m *NewAddressRequest) Reset() { *m = NewAddressRequest{} } @@ -103,6 +130,7 @@ func init() { proto.RegisterType((*NewAddressResponse)(nil), "lnrpc.NewAddressResponse") proto.RegisterType((*ConnectPeerRequest)(nil), "lnrpc.ConnectPeerRequest") proto.RegisterType((*ConnectPeerResponse)(nil), "lnrpc.ConnectPeerResponse") + proto.RegisterEnum("lnrpc.NewAddressRequest_AddressType", NewAddressRequest_AddressType_name, NewAddressRequest_AddressType_value) } // Reference imports to suppress errors if they are not otherwise used. @@ -243,24 +271,28 @@ var _Lightning_serviceDesc = grpc.ServiceDesc{ } var fileDescriptor0 = []byte{ - // 297 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x92, 0xd1, 0x4e, 0xb3, 0x40, - 0x10, 0x85, 0x43, 0xfb, 0xf7, 0xb7, 0x1d, 0x30, 0x6d, 0xb7, 0x89, 0x22, 0x57, 0x0d, 0x46, 0xc3, - 0x15, 0x17, 0xed, 0x8d, 0xd1, 0xc4, 0x84, 0x58, 0x13, 0x4d, 0xd4, 0x18, 0xf5, 0x05, 0xb0, 0x4c, - 0x2a, 0x11, 0x67, 0x91, 0x5d, 0x54, 0x5e, 0xc0, 0xf7, 0xf3, 0x8d, 0x44, 0x58, 0x02, 0x0a, 0x97, - 0x73, 0xe6, 0x3b, 0x87, 0x33, 0x64, 0x61, 0x94, 0xc4, 0x6b, 0x37, 0x4e, 0xb8, 0xe4, 0x6c, 0x10, - 0x51, 0x3e, 0xd8, 0x9f, 0x1a, 0x8c, 0xef, 0x91, 0x82, 0x6b, 0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, - 0x73, 0x2d, 0xab, 0x6b, 0x55, 0xa6, 0x3c, 0xfe, 0x2f, 0x5e, 0xc5, 0xf2, 0x3b, 0x00, 0x00, 0xff, - 0xff, 0x15, 0x2e, 0xcf, 0x06, 0x22, 0x02, 0x00, 0x00, + // 365 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x74, 0x92, 0xcf, 0x4e, 0xea, 0x40, + 0x14, 0xc6, 0x6f, 0xe1, 0x72, 0x2f, 0x9c, 0xa2, 0xc0, 0x21, 0x01, 0xec, 0x8a, 0xd4, 0x3f, 0x61, + 0xd5, 0x45, 0xd9, 0x18, 0x4d, 0x4c, 0xaa, 0x34, 0x81, 0xa8, 0x48, 0x6c, 0x8d, 0x71, 0x45, 0x90, + 0x4e, 0xb0, 0x11, 0xa7, 0xb5, 0x1d, 0xd4, 0xbe, 0x80, 0xcf, 0xe0, 0x6b, 0xf9, 0x46, 0x8e, 0x65, + 0x1a, 0x8a, 0xc5, 0xe5, 0xf7, 0xcd, 0x6f, 0xbe, 0x7e, 0xe7, 0x74, 0xa0, 0x14, 0xf8, 0x53, 0xcd, + 0x0f, 0x3c, 0xe6, 0x61, 0x61, 0x4e, 0xb9, 0x50, 0xdf, 0x25, 0xa8, 0x58, 0x84, 0x3a, 0x97, 0x13, + 0x1a, 0x5d, 0x93, 0xe7, 0x05, 0x09, 0x19, 0x9e, 0x40, 0xd9, 0x70, 0x9c, 0xc0, 0xf6, 0x8c, 0x27, + 0x6f, 0x41, 0x59, 0x4b, 0x6a, 0xe7, 0x3b, 0xb2, 0xde, 0xd1, 0xe2, 0x1b, 0xda, 0x0f, 0x5a, 0x4b, + 0xa3, 0x26, 0x65, 0x41, 0xa4, 0x74, 0xa1, 0x96, 0x31, 0x51, 0x86, 0xfc, 0x23, 0x89, 0x78, 0x96, + 0xd4, 0x29, 0xe1, 0x16, 0x14, 0x5e, 0x26, 0xf3, 0x05, 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, + 0x26, 0x64, 0x76, 0x5c, 0x45, 0xd9, 0x74, 0xb4, 0x4c, 0xb9, 0xff, 0x17, 0xbf, 0xcd, 0xee, 0x57, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x25, 0x4b, 0x6e, 0x48, 0xa8, 0x02, 0x00, 0x00, } diff --git a/lnrpc/rpc.proto b/lnrpc/rpc.proto index 903da85a..2ae96e08 100644 --- a/lnrpc/rpc.proto +++ b/lnrpc/rpc.proto @@ -17,8 +17,15 @@ message SendManyResponse { string txid = 1; } -message NewAddressRequest {} +message NewAddressRequest { + enum AddressType { + WITNESS_PUBKEY_HASH = 0; + NESTED_PUBKEY_HASH = 1; + PUBKEY_HASH = 2; + } + AddressType type = 1; +} message NewAddressResponse { string address = 1; } diff --git a/rpcserver.go b/rpcserver.go index 74097fb1..85ba355d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1,7 +1,6 @@ package main import ( - "encoding/hex" "fmt" "sync" @@ -54,6 +53,8 @@ func (r *rpcServer) Stop() error { return nil } + close(r.quit) + return nil } @@ -80,16 +81,32 @@ func (r *rpcServer) SendMany(ctx context.Context, in *lnrpc.SendManyRequest) (*l return nil, err } - return &lnrpc.SendManyResponse{Txid: hex.EncodeToString(txid[:])}, nil + rpcsLog.Infof("Generated txid: %v", txid.String()) + + return &lnrpc.SendManyResponse{Txid: txid.String()}, nil } // NewAddress... -func (r *rpcServer) NewAddress(ctx context.Context, in *lnrpc.NewAddressRequest) (*lnrpc.NewAddressResponse, error) { +func (r *rpcServer) NewAddress(ctx context.Context, + in *lnrpc.NewAddressRequest) (*lnrpc.NewAddressResponse, error) { r.server.lnwallet.KeyGenMtx.Lock() defer r.server.lnwallet.KeyGenMtx.Unlock() - addr, err := r.server.lnwallet.NewAddress(defaultAccount) + // Translate the gRPC proto address type to the wallet controller's + // available address types. + var addrType waddrmgr.AddressType + switch in.Type { + case lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH: + addrType = waddrmgr.WitnessPubKey + case lnrpc.NewAddressRequest_NESTED_PUBKEY_HASH: + addrType = waddrmgr.NestedWitnessPubKey + case lnrpc.NewAddressRequest_PUBKEY_HASH: + addrType = waddrmgr.PubKeyHash + } + + addr, err := r.server.lnwallet.NewAddress(defaultAccount, + addrType) if err != nil { return nil, err }