From b0f5086ec0f3b7c20a99ec15c2aee46f2226ce83 Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Tue, 29 Oct 2019 17:33:21 -0700 Subject: [PATCH 1/5] update to latest ledger protos --- protos/ledger/ledger.pb.go | 236 ++++++++++++++++++++++++++++--------- protos/ledger/ledger.proto | 11 ++ 2 files changed, 193 insertions(+), 54 deletions(-) diff --git a/protos/ledger/ledger.pb.go b/protos/ledger/ledger.pb.go index 8289a67..f54a3d7 100644 --- a/protos/ledger/ledger.pb.go +++ b/protos/ledger/ledger.pb.go @@ -92,6 +92,53 @@ func (m *PublicKey) GetKey() []byte { return nil } +type SignedPublicKey struct { + Key *PublicKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SignedPublicKey) Reset() { *m = SignedPublicKey{} } +func (m *SignedPublicKey) String() string { return proto.CompactTextString(m) } +func (*SignedPublicKey) ProtoMessage() {} +func (*SignedPublicKey) Descriptor() ([]byte, []int) { + return fileDescriptor_858b35020cfe9185, []int{2} +} + +func (m *SignedPublicKey) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SignedPublicKey.Unmarshal(m, b) +} +func (m *SignedPublicKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SignedPublicKey.Marshal(b, m, deterministic) +} +func (m *SignedPublicKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignedPublicKey.Merge(m, src) +} +func (m *SignedPublicKey) XXX_Size() int { + return xxx_messageInfo_SignedPublicKey.Size(m) +} +func (m *SignedPublicKey) XXX_DiscardUnknown() { + xxx_messageInfo_SignedPublicKey.DiscardUnknown(m) +} + +var xxx_messageInfo_SignedPublicKey proto.InternalMessageInfo + +func (m *SignedPublicKey) GetKey() *PublicKey { + if m != nil { + return m.Key + } + return nil +} + +func (m *SignedPublicKey) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + type ChannelCommit struct { Payer *PublicKey `protobuf:"bytes,1,opt,name=payer,proto3" json:"payer,omitempty"` Recipient *PublicKey `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` @@ -106,7 +153,7 @@ func (m *ChannelCommit) Reset() { *m = ChannelCommit{} } func (m *ChannelCommit) String() string { return proto.CompactTextString(m) } func (*ChannelCommit) ProtoMessage() {} func (*ChannelCommit) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{2} + return fileDescriptor_858b35020cfe9185, []int{3} } func (m *ChannelCommit) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ChannelCommit.Unmarshal(m, b) @@ -166,7 +213,7 @@ func (m *SignedChannelCommit) Reset() { *m = SignedChannelCommit{} } func (m *SignedChannelCommit) String() string { return proto.CompactTextString(m) } func (*SignedChannelCommit) ProtoMessage() {} func (*SignedChannelCommit) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{3} + return fileDescriptor_858b35020cfe9185, []int{4} } func (m *SignedChannelCommit) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SignedChannelCommit.Unmarshal(m, b) @@ -211,7 +258,7 @@ func (m *CreateAccountResult) Reset() { *m = CreateAccountResult{} } func (m *CreateAccountResult) String() string { return proto.CompactTextString(m) } func (*CreateAccountResult) ProtoMessage() {} func (*CreateAccountResult) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{4} + return fileDescriptor_858b35020cfe9185, []int{5} } func (m *CreateAccountResult) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CreateAccountResult.Unmarshal(m, b) @@ -238,6 +285,45 @@ func (m *CreateAccountResult) GetAccount() *Account { return nil } +type SignedCreateAccountResult struct { + Balance int64 `protobuf:"varint,1,opt,name=balance,proto3" json:"balance,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SignedCreateAccountResult) Reset() { *m = SignedCreateAccountResult{} } +func (m *SignedCreateAccountResult) String() string { return proto.CompactTextString(m) } +func (*SignedCreateAccountResult) ProtoMessage() {} +func (*SignedCreateAccountResult) Descriptor() ([]byte, []int) { + return fileDescriptor_858b35020cfe9185, []int{6} +} + +func (m *SignedCreateAccountResult) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SignedCreateAccountResult.Unmarshal(m, b) +} +func (m *SignedCreateAccountResult) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SignedCreateAccountResult.Marshal(b, m, deterministic) +} +func (m *SignedCreateAccountResult) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignedCreateAccountResult.Merge(m, src) +} +func (m *SignedCreateAccountResult) XXX_Size() int { + return xxx_messageInfo_SignedCreateAccountResult.Size(m) +} +func (m *SignedCreateAccountResult) XXX_DiscardUnknown() { + xxx_messageInfo_SignedCreateAccountResult.DiscardUnknown(m) +} + +var xxx_messageInfo_SignedCreateAccountResult proto.InternalMessageInfo + +func (m *SignedCreateAccountResult) GetBalance() int64 { + if m != nil { + return m.Balance + } + return 0 +} + type Account struct { Address *PublicKey `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // Current available balance @@ -251,7 +337,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{5} + return fileDescriptor_858b35020cfe9185, []int{7} } func (m *Account) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Account.Unmarshal(m, b) @@ -296,7 +382,7 @@ func (m *ChannelID) Reset() { *m = ChannelID{} } func (m *ChannelID) String() string { return proto.CompactTextString(m) } func (*ChannelID) ProtoMessage() {} func (*ChannelID) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{6} + return fileDescriptor_858b35020cfe9185, []int{8} } func (m *ChannelID) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ChannelID.Unmarshal(m, b) @@ -337,7 +423,7 @@ func (m *ChannelInfo) Reset() { *m = ChannelInfo{} } func (m *ChannelInfo) String() string { return proto.CompactTextString(m) } func (*ChannelInfo) ProtoMessage() {} func (*ChannelInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{7} + return fileDescriptor_858b35020cfe9185, []int{9} } func (m *ChannelInfo) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ChannelInfo.Unmarshal(m, b) @@ -398,7 +484,7 @@ func (m *SignedChannelState) Reset() { *m = SignedChannelState{} } func (m *SignedChannelState) String() string { return proto.CompactTextString(m) } func (*SignedChannelState) ProtoMessage() {} func (*SignedChannelState) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{8} + return fileDescriptor_858b35020cfe9185, []int{10} } func (m *SignedChannelState) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SignedChannelState.Unmarshal(m, b) @@ -451,7 +537,7 @@ func (m *ClosedChannelCursor) Reset() { *m = ClosedChannelCursor{} } func (m *ClosedChannelCursor) String() string { return proto.CompactTextString(m) } func (*ClosedChannelCursor) ProtoMessage() {} func (*ClosedChannelCursor) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{9} + return fileDescriptor_858b35020cfe9185, []int{11} } func (m *ClosedChannelCursor) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ClosedChannelCursor.Unmarshal(m, b) @@ -499,7 +585,7 @@ func (m *ChannelState) Reset() { *m = ChannelState{} } func (m *ChannelState) String() string { return proto.CompactTextString(m) } func (*ChannelState) ProtoMessage() {} func (*ChannelState) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{10} + return fileDescriptor_858b35020cfe9185, []int{12} } func (m *ChannelState) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ChannelState.Unmarshal(m, b) @@ -558,7 +644,7 @@ func (m *ChannelClosed) Reset() { *m = ChannelClosed{} } func (m *ChannelClosed) String() string { return proto.CompactTextString(m) } func (*ChannelClosed) ProtoMessage() {} func (*ChannelClosed) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{11} + return fileDescriptor_858b35020cfe9185, []int{13} } func (m *ChannelClosed) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ChannelClosed.Unmarshal(m, b) @@ -599,7 +685,7 @@ func (m *SignedPublicKeyPair) Reset() { *m = SignedPublicKeyPair{} } func (m *SignedPublicKeyPair) String() string { return proto.CompactTextString(m) } func (*SignedPublicKeyPair) ProtoMessage() {} func (*SignedPublicKeyPair) Descriptor() ([]byte, []int) { - return fileDescriptor_858b35020cfe9185, []int{12} + return fileDescriptor_858b35020cfe9185, []int{14} } func (m *SignedPublicKeyPair) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SignedPublicKeyPair.Unmarshal(m, b) @@ -650,9 +736,11 @@ func (m *SignedPublicKeyPair) GetNewSignature() []byte { func init() { proto.RegisterType((*Null)(nil), "ledger.Null") proto.RegisterType((*PublicKey)(nil), "ledger.PublicKey") + proto.RegisterType((*SignedPublicKey)(nil), "ledger.SignedPublicKey") proto.RegisterType((*ChannelCommit)(nil), "ledger.ChannelCommit") proto.RegisterType((*SignedChannelCommit)(nil), "ledger.SignedChannelCommit") proto.RegisterType((*CreateAccountResult)(nil), "ledger.CreateAccountResult") + proto.RegisterType((*SignedCreateAccountResult)(nil), "ledger.SignedCreateAccountResult") proto.RegisterType((*Account)(nil), "ledger.Account") proto.RegisterType((*ChannelID)(nil), "ledger.ChannelID") proto.RegisterType((*ChannelInfo)(nil), "ledger.ChannelInfo") @@ -666,50 +754,52 @@ func init() { func init() { proto.RegisterFile("protos/ledger/ledger.proto", fileDescriptor_858b35020cfe9185) } var fileDescriptor_858b35020cfe9185 = []byte{ - // 679 bytes of a gzipped FileDescriptorProto + // 720 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x95, 0xed, 0x34, 0x6e, 0x26, 0x4e, 0x80, 0x4d, 0x41, 0xc1, 0x05, 0xd1, 0xba, 0xaa, 0x28, - 0x45, 0x4a, 0x51, 0xb9, 0x70, 0xa3, 0x55, 0x90, 0x4a, 0x85, 0x54, 0x45, 0x8e, 0x38, 0x47, 0x8e, - 0x77, 0x5a, 0x2c, 0x1c, 0x6f, 0xb0, 0xd7, 0x2a, 0xfd, 0x09, 0x2e, 0x88, 0x1b, 0xff, 0xc1, 0x81, - 0x9f, 0x43, 0xbb, 0xf6, 0xda, 0x89, 0xed, 0xa0, 0x9e, 0x92, 0x7d, 0xf3, 0x76, 0x76, 0xde, 0xbc, - 0xdd, 0x31, 0xd8, 0xcb, 0x98, 0x71, 0x96, 0x9c, 0x84, 0x48, 0x6f, 0x30, 0xce, 0x7f, 0x46, 0x12, - 0x24, 0xed, 0x6c, 0xe5, 0xb4, 0xa1, 0x75, 0x95, 0x86, 0xa1, 0xf3, 0x1c, 0x3a, 0x93, 0x74, 0x1e, - 0x06, 0xfe, 0x27, 0xbc, 0x23, 0x0f, 0xc1, 0xf8, 0x8a, 0x77, 0x43, 0x6d, 0x4f, 0x3b, 0xb2, 0x5c, - 0xf1, 0xd7, 0xf9, 0xad, 0x41, 0x6f, 0xfc, 0xc5, 0x8b, 0x22, 0x0c, 0xc7, 0x6c, 0xb1, 0x08, 0x38, - 0x79, 0x09, 0x5b, 0x4b, 0xef, 0x0e, 0x63, 0xc9, 0xea, 0x9e, 0x3e, 0x1a, 0xe5, 0xe9, 0x8b, 0x2c, - 0x6e, 0x16, 0x27, 0x27, 0xd0, 0x89, 0xd1, 0x0f, 0x96, 0x01, 0x46, 0x7c, 0xa8, 0x6f, 0x22, 0x97, - 0x1c, 0xf2, 0x04, 0xda, 0xde, 0x82, 0xa5, 0x11, 0x1f, 0x1a, 0x7b, 0xda, 0x91, 0xe1, 0xe6, 0x2b, - 0xf2, 0x14, 0xb6, 0x65, 0xc6, 0x59, 0x40, 0x87, 0x2d, 0x19, 0x31, 0xe5, 0xfa, 0x92, 0x3a, 0x14, - 0x06, 0xd3, 0xe0, 0x26, 0x42, 0xba, 0x5e, 0xe3, 0x09, 0x98, 0x7e, 0x06, 0xe4, 0x55, 0x3e, 0x56, - 0x07, 0xaf, 0xf1, 0x5c, 0xc5, 0x22, 0xcf, 0xa0, 0x93, 0x04, 0x37, 0x91, 0xc7, 0xd3, 0x18, 0x65, - 0xad, 0x96, 0x5b, 0x02, 0xce, 0x19, 0x0c, 0xc6, 0x31, 0x7a, 0x1c, 0xcf, 0x7d, 0x5f, 0x54, 0xe4, - 0x62, 0x92, 0x86, 0x9c, 0xbc, 0x02, 0xd3, 0xcb, 0x80, 0xfc, 0x94, 0x07, 0xea, 0x14, 0xc5, 0x53, - 0x71, 0x67, 0x02, 0x66, 0x8e, 0x91, 0xd7, 0x60, 0x7a, 0x94, 0xc6, 0x98, 0x24, 0x9b, 0x3b, 0xa8, - 0x18, 0x64, 0x08, 0xe6, 0xdc, 0x0b, 0xbd, 0xc8, 0xcf, 0xaa, 0x32, 0x5c, 0xb5, 0x74, 0x76, 0xa1, - 0x93, 0x6b, 0xb9, 0xfc, 0x40, 0xfa, 0xa0, 0x07, 0x54, 0xa6, 0x33, 0x5c, 0x3d, 0xa0, 0xce, 0x5f, - 0x0d, 0xba, 0x2a, 0x1a, 0x5d, 0x33, 0xb2, 0x5f, 0xc4, 0x57, 0x8e, 0x2b, 0xb6, 0x8b, 0x2d, 0xe4, - 0x14, 0xac, 0xeb, 0x98, 0x2d, 0x66, 0x4a, 0x91, 0xde, 0xac, 0xa8, 0x2b, 0x48, 0x4a, 0xca, 0x08, - 0x80, 0xb3, 0x62, 0x87, 0xd1, 0xbc, 0xa3, 0xc3, 0x99, 0xe2, 0x1f, 0x42, 0xdf, 0x0f, 0x59, 0x82, - 0xb3, 0x04, 0xbf, 0xa5, 0x28, 0x44, 0x65, 0x76, 0xf6, 0x24, 0x3a, 0xcd, 0x41, 0xe7, 0x87, 0x06, - 0x64, 0xcd, 0xd5, 0x29, 0xf7, 0x38, 0x92, 0x51, 0xd5, 0xd4, 0x9d, 0x8a, 0x12, 0x49, 0x2b, 0x3d, - 0x3d, 0x84, 0xbe, 0x54, 0x54, 0x35, 0xb6, 0x27, 0xd0, 0xa9, 0x02, 0xc9, 0x3e, 0x58, 0x9c, 0xad, - 0x90, 0x0c, 0x49, 0xea, 0x72, 0x56, 0x50, 0x1c, 0x84, 0xc1, 0x58, 0x54, 0x58, 0xdc, 0xb2, 0x34, - 0x4e, 0x58, 0x7c, 0xff, 0x97, 0x50, 0xd7, 0xad, 0x37, 0xe9, 0xfe, 0xa9, 0x81, 0xb5, 0xa6, 0xf8, - 0x1e, 0xb6, 0xd9, 0xb0, 0x5d, 0x49, 0x5a, 0xac, 0xc9, 0x01, 0xb4, 0x84, 0xd4, 0x4d, 0xc6, 0xc8, - 0x20, 0x79, 0x01, 0x3a, 0x67, 0xd2, 0x87, 0x06, 0x8a, 0xce, 0x99, 0x73, 0x5e, 0x0e, 0x00, 0xd9, - 0x03, 0xf2, 0x06, 0xb6, 0x12, 0x51, 0x5e, 0x5e, 0x98, 0xad, 0x36, 0xd5, 0x2d, 0x73, 0x33, 0xa2, - 0xf3, 0x47, 0x53, 0xcf, 0xb4, 0x68, 0xcd, 0xc4, 0x0b, 0x62, 0x72, 0x0c, 0x26, 0x0b, 0xe9, 0x4c, - 0x8d, 0x9c, 0xc6, 0x16, 0xb6, 0x59, 0x48, 0xc5, 0x68, 0x3a, 0x06, 0x33, 0xc2, 0x5b, 0xc9, 0xdd, - 0x38, 0x4b, 0xda, 0x11, 0xde, 0x0a, 0xee, 0x01, 0xf4, 0x44, 0xde, 0xaa, 0xa7, 0x16, 0x0b, 0x69, - 0xe9, 0xfb, 0x01, 0xf4, 0x44, 0xc2, 0x92, 0xd4, 0xca, 0x48, 0x11, 0xde, 0x16, 0xa4, 0xd3, 0x5f, - 0x06, 0x6c, 0xe7, 0x8a, 0x12, 0xf2, 0x1e, 0x7a, 0xd9, 0x18, 0xc8, 0x11, 0xb2, 0xdb, 0x28, 0x3d, - 0x9b, 0x2d, 0x76, 0xdd, 0x30, 0xf2, 0x0e, 0xfa, 0x17, 0xc8, 0x57, 0x1f, 0x66, 0x9d, 0x64, 0x0f, - 0xaa, 0x90, 0xe0, 0x9d, 0x83, 0x25, 0xbb, 0xaf, 0x4e, 0xfe, 0x4f, 0xd3, 0xed, 0xda, 0xac, 0xcb, - 0x6c, 0xfb, 0x08, 0x3b, 0x17, 0xc8, 0xaf, 0xf0, 0x3b, 0x5f, 0xbb, 0xcb, 0xa5, 0x88, 0x86, 0x2b, - 0xde, 0x5c, 0x4c, 0xd1, 0x07, 0xf5, 0xae, 0xeb, 0x56, 0xd8, 0x65, 0xd6, 0x86, 0xc1, 0x79, 0x06, - 0x83, 0xcf, 0x4b, 0x5a, 0xc2, 0x93, 0x74, 0x2e, 0x6c, 0xab, 0xb4, 0x73, 0xed, 0xae, 0xd8, 0x96, - 0x0a, 0x8a, 0xaf, 0xd6, 0xbc, 0x2d, 0x3f, 0x66, 0x6f, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x1f, - 0x72, 0xd6, 0xf1, 0xea, 0x06, 0x00, 0x00, + 0x10, 0x95, 0x9d, 0x34, 0x6e, 0x26, 0x4e, 0x0a, 0x9b, 0x02, 0xa9, 0x0b, 0xa2, 0x75, 0x55, 0x51, + 0x8a, 0x94, 0xa2, 0x22, 0x24, 0x6e, 0xb4, 0x0a, 0x52, 0xa9, 0x90, 0xaa, 0x90, 0xc0, 0x39, 0x72, + 0xec, 0x69, 0xb1, 0x70, 0xbc, 0xc1, 0x5e, 0xab, 0xf4, 0x27, 0xb8, 0x70, 0xe5, 0x3f, 0x38, 0xf0, + 0x43, 0x7c, 0x06, 0xda, 0xf5, 0xae, 0x1d, 0x3b, 0x4e, 0xe9, 0x29, 0xd9, 0x99, 0xb7, 0x6f, 0xe6, + 0xcd, 0xcc, 0x8e, 0xc1, 0x9a, 0x47, 0x94, 0xd1, 0xf8, 0x28, 0x40, 0xef, 0x0a, 0x23, 0xf9, 0xd3, + 0x17, 0x46, 0xd2, 0x48, 0x4f, 0x76, 0x03, 0xea, 0x17, 0x49, 0x10, 0xd8, 0x4f, 0xa0, 0x39, 0x4c, + 0xa6, 0x81, 0xef, 0x7e, 0xc0, 0x1b, 0x72, 0x0f, 0x6a, 0x5f, 0xf1, 0xa6, 0xa7, 0xed, 0x68, 0x07, + 0xe6, 0x88, 0xff, 0xb5, 0x3f, 0xc1, 0xc6, 0xd8, 0xbf, 0x0a, 0xd1, 0xcb, 0x41, 0x7b, 0x39, 0xa8, + 0x75, 0x7c, 0xbf, 0x2f, 0xd9, 0x33, 0xbf, 0xb8, 0x47, 0x1e, 0x43, 0x33, 0xf6, 0xaf, 0x42, 0x87, + 0x25, 0x11, 0xf6, 0x74, 0xc1, 0x97, 0x1b, 0xec, 0x5f, 0x1a, 0xb4, 0x07, 0x5f, 0x9c, 0x30, 0xc4, + 0x60, 0x40, 0x67, 0x33, 0x9f, 0x91, 0x67, 0xb0, 0x36, 0x77, 0x6e, 0x30, 0x5a, 0x4d, 0x9b, 0xfa, + 0xc9, 0x11, 0x34, 0x23, 0x74, 0xfd, 0xb9, 0x8f, 0x21, 0x13, 0xc4, 0x95, 0xe0, 0x1c, 0x43, 0x1e, + 0x42, 0xc3, 0x99, 0xd1, 0x24, 0x64, 0xbd, 0xda, 0x8e, 0x76, 0x50, 0x1b, 0xc9, 0x13, 0xd9, 0x82, + 0x75, 0xc1, 0x38, 0xf1, 0xbd, 0x5e, 0x5d, 0x78, 0x0c, 0x71, 0x3e, 0xf7, 0x6c, 0x0f, 0xba, 0xa9, + 0xe8, 0x62, 0x8e, 0x47, 0x60, 0xb8, 0xa9, 0x41, 0x66, 0xf9, 0x40, 0x05, 0x2e, 0xe0, 0x46, 0x0a, + 0xf5, 0x9f, 0x22, 0x9c, 0x40, 0x77, 0x10, 0xa1, 0xc3, 0xf0, 0xd4, 0x75, 0x79, 0x46, 0x23, 0x8c, + 0x93, 0x80, 0x91, 0xe7, 0x60, 0x38, 0xa9, 0x41, 0x46, 0xd9, 0x50, 0x51, 0x14, 0x4e, 0xf9, 0xed, + 0xd7, 0xb0, 0x25, 0xf3, 0xac, 0xe0, 0xe9, 0x81, 0x31, 0x75, 0x02, 0x27, 0x74, 0x51, 0xf0, 0xd4, + 0x46, 0xea, 0x68, 0x0f, 0xc1, 0x90, 0x50, 0xf2, 0x02, 0x0c, 0xc7, 0xf3, 0x22, 0x8c, 0xe3, 0xd5, + 0x85, 0x57, 0x88, 0x45, 0x46, 0xbd, 0xc8, 0xb8, 0x0d, 0x4d, 0x59, 0x82, 0xf3, 0x77, 0xa4, 0x03, + 0xba, 0xef, 0xc9, 0x98, 0xba, 0xef, 0xd9, 0x7f, 0x34, 0x68, 0x29, 0x6f, 0x78, 0x49, 0xc9, 0x6e, + 0xe6, 0x5f, 0x08, 0x97, 0x5d, 0xe7, 0x57, 0xc8, 0x31, 0x98, 0x97, 0x11, 0x9d, 0x4d, 0x54, 0x21, + 0xf4, 0xea, 0x42, 0xb4, 0x38, 0x48, 0x49, 0xe9, 0x03, 0x30, 0x9a, 0xdd, 0xa8, 0x55, 0xdf, 0x68, + 0x32, 0xaa, 0xf0, 0xfb, 0xd0, 0x71, 0x03, 0x1a, 0xe3, 0x24, 0xc6, 0x6f, 0x09, 0x72, 0x51, 0xe9, + 0x14, 0xb4, 0x85, 0x75, 0x2c, 0x8d, 0xf6, 0x0f, 0x0d, 0x48, 0x61, 0x18, 0xc6, 0xcc, 0x61, 0x48, + 0xfa, 0xe5, 0x59, 0xd8, 0x2c, 0x29, 0x11, 0xb0, 0x7c, 0x14, 0xf6, 0xa1, 0x23, 0x14, 0x95, 0xe7, + 0xa1, 0xcd, 0xad, 0x63, 0x65, 0x24, 0xbb, 0x60, 0x32, 0xba, 0x00, 0xaa, 0x09, 0x50, 0x8b, 0xd1, + 0x0c, 0x62, 0x23, 0x74, 0x07, 0x3c, 0xc3, 0x6c, 0x38, 0x93, 0x28, 0xa6, 0xd1, 0xdd, 0x1f, 0xd0, + 0xb2, 0x6e, 0xbd, 0x4a, 0xf7, 0x4f, 0x0d, 0xcc, 0x82, 0xe2, 0x3b, 0xb4, 0xcd, 0x82, 0xf5, 0x12, + 0x69, 0x76, 0x26, 0x7b, 0x50, 0xe7, 0x52, 0x57, 0x35, 0x46, 0x38, 0xc9, 0x53, 0xd0, 0x19, 0x15, + 0x7d, 0xa8, 0x80, 0xe8, 0x8c, 0xda, 0xa7, 0xf9, 0xde, 0x10, 0x35, 0x20, 0x2f, 0x61, 0x2d, 0xe6, + 0xe9, 0xc9, 0xc4, 0x2c, 0x75, 0x69, 0xb9, 0x65, 0xa3, 0x14, 0x68, 0xff, 0xd6, 0xd4, 0xeb, 0xce, + 0x4a, 0x33, 0x74, 0xfc, 0x88, 0x1c, 0x82, 0x41, 0x03, 0x6f, 0x72, 0xeb, 0x6a, 0x6b, 0xd0, 0xc0, + 0xe3, 0x2b, 0xf0, 0x10, 0x8c, 0x10, 0xaf, 0x05, 0x76, 0xe5, 0x0a, 0x6a, 0x84, 0x78, 0x9d, 0xae, + 0xcb, 0x36, 0xe7, 0x2d, 0xf7, 0xd4, 0xa4, 0x81, 0x97, 0xf7, 0x7d, 0x0f, 0xda, 0x9c, 0x30, 0x07, + 0xd5, 0x53, 0x50, 0x88, 0xd7, 0x19, 0xe8, 0xf8, 0x6f, 0x0d, 0xd6, 0xa5, 0xa2, 0x98, 0xbc, 0x85, + 0x76, 0xfa, 0xea, 0xa5, 0x85, 0x6c, 0x57, 0x4a, 0x4f, 0x57, 0x92, 0xb5, 0xdc, 0x30, 0xf2, 0x06, + 0x3a, 0x67, 0xc8, 0x16, 0x1f, 0xe6, 0x32, 0xc8, 0xea, 0x96, 0x4d, 0x1c, 0x77, 0x0a, 0xa6, 0xa8, + 0xbe, 0x8a, 0x7c, 0x4b, 0xd1, 0xad, 0xa5, 0x15, 0x99, 0xb6, 0xed, 0x3d, 0x6c, 0x9e, 0x21, 0xbb, + 0xc0, 0xef, 0xac, 0x30, 0xcb, 0xb9, 0x88, 0x8a, 0x11, 0xaf, 0x4e, 0x26, 0xab, 0x83, 0x7a, 0xd7, + 0xcb, 0xad, 0xb0, 0x72, 0xd6, 0x8a, 0x3d, 0xf9, 0x31, 0x5b, 0xf6, 0x05, 0x9a, 0x47, 0x45, 0x51, + 0x39, 0xd9, 0x6e, 0x49, 0x6d, 0x05, 0xe5, 0x09, 0x74, 0x3f, 0xcf, 0xbd, 0xdc, 0x3c, 0x4c, 0xa6, + 0x7c, 0x12, 0xb6, 0x57, 0x50, 0xf2, 0xf1, 0xb3, 0x4c, 0xe5, 0xe4, 0x5f, 0xe5, 0x69, 0x43, 0x7c, + 0xac, 0x5f, 0xfd, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xc2, 0x12, 0x86, 0xe3, 0xca, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -735,6 +825,8 @@ type ChannelsClient interface { GetNextClosedChannel(ctx context.Context, in *ClosedChannelCursor, opts ...grpc.CallOption) (*ChannelInfo, error) // Create an account and return CreateAccount(ctx context.Context, in *PublicKey, opts ...grpc.CallOption) (*CreateAccountResult, error) + // Create an account, securely, and return + SignedCreateAccount(ctx context.Context, in *SignedPublicKey, opts ...grpc.CallOption) (*SignedCreateAccountResult, error) // Update an account pub key (BIP 44 compatible) UpdateAccountPubKey(ctx context.Context, in *SignedPublicKeyPair, opts ...grpc.CallOption) (*Null, error) } @@ -792,6 +884,15 @@ func (c *channelsClient) CreateAccount(ctx context.Context, in *PublicKey, opts return out, nil } +func (c *channelsClient) SignedCreateAccount(ctx context.Context, in *SignedPublicKey, opts ...grpc.CallOption) (*SignedCreateAccountResult, error) { + out := new(SignedCreateAccountResult) + err := c.cc.Invoke(ctx, "/ledger.Channels/SignedCreateAccount", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *channelsClient) UpdateAccountPubKey(ctx context.Context, in *SignedPublicKeyPair, opts ...grpc.CallOption) (*Null, error) { out := new(Null) err := c.cc.Invoke(ctx, "/ledger.Channels/UpdateAccountPubKey", in, out, opts...) @@ -814,6 +915,8 @@ type ChannelsServer interface { GetNextClosedChannel(context.Context, *ClosedChannelCursor) (*ChannelInfo, error) // Create an account and return CreateAccount(context.Context, *PublicKey) (*CreateAccountResult, error) + // Create an account, securely, and return + SignedCreateAccount(context.Context, *SignedPublicKey) (*SignedCreateAccountResult, error) // Update an account pub key (BIP 44 compatible) UpdateAccountPubKey(context.Context, *SignedPublicKeyPair) (*Null, error) } @@ -837,6 +940,9 @@ func (*UnimplementedChannelsServer) GetNextClosedChannel(ctx context.Context, re func (*UnimplementedChannelsServer) CreateAccount(ctx context.Context, req *PublicKey) (*CreateAccountResult, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateAccount not implemented") } +func (*UnimplementedChannelsServer) SignedCreateAccount(ctx context.Context, req *SignedPublicKey) (*SignedCreateAccountResult, error) { + return nil, status.Errorf(codes.Unimplemented, "method SignedCreateAccount not implemented") +} func (*UnimplementedChannelsServer) UpdateAccountPubKey(ctx context.Context, req *SignedPublicKeyPair) (*Null, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateAccountPubKey not implemented") } @@ -935,6 +1041,24 @@ func _Channels_CreateAccount_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } +func _Channels_SignedCreateAccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SignedPublicKey) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ChannelsServer).SignedCreateAccount(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ledger.Channels/SignedCreateAccount", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ChannelsServer).SignedCreateAccount(ctx, req.(*SignedPublicKey)) + } + return interceptor(ctx, in, info, handler) +} + func _Channels_UpdateAccountPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SignedPublicKeyPair) if err := dec(in); err != nil { @@ -977,6 +1101,10 @@ var _Channels_serviceDesc = grpc.ServiceDesc{ MethodName: "CreateAccount", Handler: _Channels_CreateAccount_Handler, }, + { + MethodName: "SignedCreateAccount", + Handler: _Channels_SignedCreateAccount_Handler, + }, { MethodName: "UpdateAccountPubKey", Handler: _Channels_UpdateAccountPubKey_Handler, diff --git a/protos/ledger/ledger.proto b/protos/ledger/ledger.proto index f297c52..2c5e720 100755 --- a/protos/ledger/ledger.proto +++ b/protos/ledger/ledger.proto @@ -16,6 +16,8 @@ service Channels { rpc GetNextClosedChannel(ClosedChannelCursor) returns (ChannelInfo); // Create an account and return rpc CreateAccount(PublicKey) returns (CreateAccountResult); + // Create an account, securely, and return + rpc SignedCreateAccount(SignedPublicKey) returns (SignedCreateAccountResult); // Update an account pub key (BIP 44 compatible) rpc UpdateAccountPubKey(SignedPublicKeyPair) returns (Null); } @@ -26,6 +28,11 @@ message PublicKey { bytes key = 1; } +message SignedPublicKey { + PublicKey key = 1; + bytes signature = 2; +} + message ChannelCommit { PublicKey payer = 1; PublicKey recipient = 2; @@ -42,6 +49,10 @@ message CreateAccountResult { Account account = 1; } +message SignedCreateAccountResult { + int64 balance = 1; +} + message Account { PublicKey address = 1; // Current available balance From 192a2dabcedb281e3441bbf7b6a6f6dd34914cb2 Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Wed, 30 Oct 2019 13:31:46 -0700 Subject: [PATCH 2/5] add ledger.go --- go.mod | 2 + go.sum | 132 +++++++++++++++++++++++++++++++++ ledger/ledger.go | 187 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 321 insertions(+) create mode 100644 ledger/ledger.go diff --git a/go.mod b/go.mod index 5d779d5..c32318e 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,7 @@ go 1.13 require ( github.com/gogo/protobuf v1.3.1 + github.com/ipfs/go-log v0.0.1 + github.com/libp2p/go-libp2p-core v0.2.4 google.golang.org/grpc v1.24.0 ) diff --git a/go.sum b/go.sum index c69e62c..7d46188 100644 --- a/go.sum +++ b/go.sum @@ -1,32 +1,164 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0= +github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= +github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= +github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= +github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= +github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= +github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= +github.com/libp2p/go-libp2p-core v0.2.4 h1:Et6ykkTwI6PU44tr8qUF9k43vP0aduMNniShAbUJJw8= +github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= +github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= +github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= +github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= +github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= +github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= +github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= +github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= +github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= +github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= +github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= +github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= +github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/src-d/envconfig v1.0.0/go.mod h1:Q9YQZ7BKITldTBnoxsE5gOeB5y66RyPXeue/R4aaNBc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= +github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= +github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= +go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181130052023-1c3d964395ce/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb h1:i1Ppqkc3WQXikh8bXiwHqAN5Rv3/qDCcRk0/Otx73BY= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/src-d/go-cli.v0 v0.0.0-20181105080154-d492247bbc0d/go.mod h1:z+K8VcOYVYcSwSjGebuDL6176A1XskgbtNl64NSg+n8= +gopkg.in/src-d/go-log.v1 v1.0.1/go.mod h1:GN34hKP0g305ysm2/hctJ0Y8nWP3zxXXJ8GFabTyABE= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/ledger/ledger.go b/ledger/ledger.go new file mode 100644 index 0000000..c10d6e5 --- /dev/null +++ b/ledger/ledger.go @@ -0,0 +1,187 @@ +package ledger + +import ( + "context" + "crypto/tls" + "crypto/x509" + "fmt" + "time" + + ledgerPb "github.com/tron-us/go-btfs-common/protos/ledger" + + "github.com/gogo/protobuf/proto" + logging "github.com/ipfs/go-log" + ic "github.com/libp2p/go-libp2p-core/crypto" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" +) + +var log = logging.Logger("ledger") +var ( + ledgerAddr = "ledger-nginx.bt.co:443" + certFile = `-----BEGIN CERTIFICATE----- +MIIEADCCAuigAwIBAgIBADANBgkqhkiG9w0BAQUFADBjMQswCQYDVQQGEwJVUzEh +MB8GA1UEChMYVGhlIEdvIERhZGR5IEdyb3VwLCBJbmMuMTEwLwYDVQQLEyhHbyBE +YWRkeSBDbGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTA0MDYyOTE3 +MDYyMFoXDTM0MDYyOTE3MDYyMFowYzELMAkGA1UEBhMCVVMxITAfBgNVBAoTGFRo +ZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28gRGFkZHkgQ2xhc3Mg +MiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCCASAwDQYJKoZIhvcNAQEBBQADggEN +ADCCAQgCggEBAN6d1+pXGEmhW+vXX0iG6r7d/+TvZxz0ZWizV3GgXne77ZtJ6XCA +PVYYYwhv2vLM0D9/AlQiVBDYsoHUwHU9S3/Hd8M+eKsaA7Ugay9qK7HFiH7Eux6w +wdhFJ2+qN1j3hybX2C32qRe3H3I2TqYXP2WYktsqbl2i/ojgC95/5Y0V4evLOtXi +EqITLdiOr18SPaAIBQi2XKVlOARFmR6jYGB0xUGlcmIbYsUfb18aQr4CUWWoriMY +avx4A6lNf4DD+qta/KFApMoZFv6yyO9ecw3ud72a9nmYvLEHZ6IVDd2gWMZEewo+ +YihfukEHU1jPEX44dMX4/7VpkI+EdOqXG68CAQOjgcAwgb0wHQYDVR0OBBYEFNLE +sNKR1EwRcbNhyz2h/t2oatTjMIGNBgNVHSMEgYUwgYKAFNLEsNKR1EwRcbNhyz2h +/t2oatTjoWekZTBjMQswCQYDVQQGEwJVUzEhMB8GA1UEChMYVGhlIEdvIERhZGR5 +IEdyb3VwLCBJbmMuMTEwLwYDVQQLEyhHbyBEYWRkeSBDbGFzcyAyIENlcnRpZmlj +YXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQAD +ggEBADJL87LKPpH8EsahB4yOd6AzBhRckB4Y9wimPQoZ+YeAEW5p5JYXMP80kWNy +OO7MHAGjHZQopDH2esRU1/blMVgDoszOYtuURXO1v0XJJLXVggKtI3lpjbi2Tc7P +TMozI+gciKqdi0FuFskg5YmezTvacPd+mSYgFFQlq25zheabIZ0KbIIOqPjCDPoQ +HmyW74cNxA9hi63ugyuV+I6ShHI56yDqg+2DzZduCLzrTia2cyvk0/ZM/iZx4mER +dEr/VxqHD3VILs9RaRegAhJhldXRQLIQTO7ErBBDpqWeCtWVYpoNz4iCxTIM5Cuf +ReYNnyicsbkqWletNw+vHX/bvZ8= +-----END CERTIFICATE-----` +) + +func LedgerConnection() (*grpc.ClientConn, error) { + var grpcOption grpc.DialOption + if certFile == "" { + grpcOption = grpc.WithInsecure() + } else { + b := []byte(certFile) + cp := x509.NewCertPool() + if !cp.AppendCertsFromPEM(b) { + return nil, fmt.Errorf("credentials: failed to append certificates") + } + credential := credentials.NewTLS(&tls.Config{RootCAs: cp}) + grpcOption = grpc.WithTransportCredentials(credential) + } + conn, err := grpc.Dial(ledgerAddr, grpcOption) + if err != nil { + return nil, err + } + return conn, nil +} + +func CloseConnection(conn *grpc.ClientConn) { + if conn != nil { + if err := conn.Close(); err != nil { + log.Error("Failed to close connection: ", err) + } + } +} + +func NewClient(conn *grpc.ClientConn) ledgerPb.ChannelsClient { + return ledgerPb.NewChannelsClient(conn) +} + +func NewAccount(pubKey ic.PubKey, amount int64) (*ledgerPb.Account, error) { + addr, err := pubKey.Raw() + if err != nil { + return nil, err + } + return &ledgerPb.Account{ + Address: &ledgerPb.PublicKey{Key: addr}, + Balance: amount, + }, nil +} + +func NewChannelCommit(fromKey ic.PubKey, toKey ic.PubKey, amount int64) (*ledgerPb.ChannelCommit, error) { + fromAddr, err := fromKey.Raw() + if err != nil { + return nil, err + } + toAddr, err := toKey.Raw() + if err != nil { + return nil, err + } + return &ledgerPb.ChannelCommit{ + Payer: &ledgerPb.PublicKey{Key: fromAddr}, + Recipient: &ledgerPb.PublicKey{Key: toAddr}, + Amount: amount, + PayerId: time.Now().UnixNano(), + }, err +} + +func NewChannelState(id *ledgerPb.ChannelID, sequence int64, fromAccount *ledgerPb.Account, toAccount *ledgerPb.Account) *ledgerPb.ChannelState { + return &ledgerPb.ChannelState{ + Id: id, + Sequence: sequence, + From: fromAccount, + To: toAccount, + } +} + +func NewSignedChannelState(channelState *ledgerPb.ChannelState, fromSig []byte, toSig []byte) *ledgerPb.SignedChannelState { + return &ledgerPb.SignedChannelState{ + Channel: channelState, + FromSignature: fromSig, + ToSignature: toSig, + } +} + +func ImportAccount(ctx context.Context, pubKey ic.PubKey, ledgerClient ledgerPb.ChannelsClient) (*ledgerPb.Account, error) { + keyBytes, err := pubKey.Raw() + if err != nil { + return nil, err + } + res, err := ledgerClient.CreateAccount(ctx, &ledgerPb.PublicKey{Key: keyBytes}) + if err != nil { + return nil, err + } + return res.GetAccount(), nil +} + +func ImportSignedAccount(ctx context.Context, privKey ic.PrivKey, pubKey ic.PubKey, ledgerClient ledgerPb.ChannelsClient) (*ledgerPb.SignedCreateAccountResult, error) { + pubKeyBytes, err := pubKey.Raw() + if err != nil { + return nil, err + } + singedPubKey := &ledgerPb.PublicKey{Key: pubKeyBytes} + sigBytes, err := proto.Marshal(singedPubKey) + signature, err := privKey.Sign(sigBytes) + if err != nil { + return nil, err + } + signedPubkey := &ledgerPb.SignedPublicKey{Key: singedPubKey, Signature: signature} + return ledgerClient.SignedCreateAccount(ctx, signedPubkey) +} + +func CreateChannel(ctx context.Context, ledgerClient ledgerPb.ChannelsClient, channelCommit *ledgerPb.ChannelCommit, sig []byte) (*ledgerPb.ChannelID, error) { + return ledgerClient.CreateChannel(ctx, &ledgerPb.SignedChannelCommit{ + Channel: channelCommit, + Signature: sig, + }) +} + +func CloseChannel(ctx context.Context, signedChannelState *ledgerPb.SignedChannelState) error { + clientConn, err := LedgerConnection() + defer CloseConnection(clientConn) + if err != nil { + return err + } + ledgerClient := NewClient(clientConn) + _, err = ledgerClient.CloseChannel(ctx, signedChannelState) + if err != nil { + return err + } + return nil +} + +func Sign(key ic.PrivKey, channelMessage proto.Message) ([]byte, error) { + raw, err := proto.Marshal(channelMessage) + if err != nil { + return nil, err + } + return key.Sign(raw) +} + +func Verify(key ic.PubKey, channelMessage proto.Message, sig []byte) (bool, error) { + raw, err := proto.Marshal(channelMessage) + if err != nil { + return false, err + } + return key.Verify(raw, sig) +} \ No newline at end of file From 9c071d4882946633c7924a9d8c9d63b5d6515c6f Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Wed, 30 Oct 2019 13:57:48 -0700 Subject: [PATCH 3/5] remove ipfs dependency --- go.mod | 3 ++- go.sum | 44 ++++++++++++++++++++++++-------------------- ledger/ledger.go | 8 ++++---- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index c32318e..f1fd8ac 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,8 @@ go 1.13 require ( github.com/gogo/protobuf v1.3.1 - github.com/ipfs/go-log v0.0.1 github.com/libp2p/go-libp2p-core v0.2.4 + github.com/tron-us/go-common v1.0.1 + go.uber.org/zap v1.10.0 google.golang.org/grpc v1.24.0 ) diff --git a/go.sum b/go.sum index 7d46188..a851b28 100644 --- a/go.sum +++ b/go.sum @@ -16,11 +16,11 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/go-pg/migrations v6.7.3+incompatible/go.mod h1:DtFiob3rFxsj0He8fye6Ta4eukFW80IfdY10zb2yH1c= +github.com/go-pg/pg v0.0.0-20190627115636-374b7dab11ff/go.mod h1:F0WF9irbhGL3ZeCxAAnjE4SIVk6FyAevdGvqhs8PQdQ= github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -34,15 +34,15 @@ github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfm github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= -github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= -github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= @@ -58,17 +58,15 @@ github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+ github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= -github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= -github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= @@ -78,9 +76,10 @@ github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKT github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= -github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= @@ -91,14 +90,23 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= -github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= +github.com/tron-us/go-common v1.0.1 h1:w+jjFAabO1WrlAHS8h/dydRLQ9Zo63HennkUtNdqptI= +github.com/tron-us/go-common v1.0.1/go.mod h1:jILzJhNCAm1qKRbP7DPw1vPMQ8s2+dfEfP6wgf8I6Eo= +github.com/vmihailenco/tagparser v0.1.0/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -110,10 +118,9 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -124,18 +131,15 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181130052023-1c3d964395ce/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -145,7 +149,6 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb h1:i1Ppqkc3WQXikh8bXiwHqAN5Rv3/qDCcRk0/Otx73BY= google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -162,3 +165,4 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ= diff --git a/ledger/ledger.go b/ledger/ledger.go index c10d6e5..ab43124 100644 --- a/ledger/ledger.go +++ b/ledger/ledger.go @@ -8,15 +8,15 @@ import ( "time" ledgerPb "github.com/tron-us/go-btfs-common/protos/ledger" + "github.com/tron-us/go-common/log" "github.com/gogo/protobuf/proto" - logging "github.com/ipfs/go-log" ic "github.com/libp2p/go-libp2p-core/crypto" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "go.uber.org/zap" ) -var log = logging.Logger("ledger") var ( ledgerAddr = "ledger-nginx.bt.co:443" certFile = `-----BEGIN CERTIFICATE----- @@ -68,7 +68,7 @@ func LedgerConnection() (*grpc.ClientConn, error) { func CloseConnection(conn *grpc.ClientConn) { if conn != nil { if err := conn.Close(); err != nil { - log.Error("Failed to close connection: ", err) + log.Error("Failed to close connection: ", zap.Error(err)) } } } @@ -184,4 +184,4 @@ func Verify(key ic.PubKey, channelMessage proto.Message, sig []byte) (bool, erro return false, err } return key.Verify(raw, sig) -} \ No newline at end of file +} From dc8c025ad6fe20fd666d5a7b4cc5e1720d05e1c0 Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Wed, 30 Oct 2019 14:57:56 -0700 Subject: [PATCH 4/5] remove hard coded ledger addr and certificate --- go.sum | 13 +++++++++++++ ledger/ledger.go | 32 +++----------------------------- protos/ledger/ledger.pb.go | 2 -- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/go.sum b/go.sum index a851b28..48aafd8 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-pg/migrations v6.7.3+incompatible/go.mod h1:DtFiob3rFxsj0He8fye6Ta4eukFW80IfdY10zb2yH1c= @@ -21,6 +22,7 @@ github.com/go-pg/pg v0.0.0-20190627115636-374b7dab11ff/go.mod h1:F0WF9irbhGL3ZeC github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -55,11 +57,13 @@ github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZ github.com/libp2p/go-libp2p-core v0.2.4 h1:Et6ykkTwI6PU44tr8qUF9k43vP0aduMNniShAbUJJw8= github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= +github.com/libp2p/go-openssl v0.0.3 h1:wjlG7HvQkt4Fq4cfH33Ivpwp0omaElYEi9z26qaIkIk= github.com/libp2p/go-openssl v0.0.3/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= @@ -68,27 +72,35 @@ github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-multiaddr v0.1.1 h1:rVAztJYMhCQ7vEFr8FvxW3mS+HF2eY/oPbOMeS0ZDnE= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= +github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= +github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/src-d/envconfig v1.0.0/go.mod h1:Q9YQZ7BKITldTBnoxsE5gOeB5y66RyPXeue/R4aaNBc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/tron-us/go-common v1.0.1 h1:w+jjFAabO1WrlAHS8h/dydRLQ9Zo63HennkUtNdqptI= github.com/tron-us/go-common v1.0.1/go.mod h1:jILzJhNCAm1qKRbP7DPw1vPMQ8s2+dfEfP6wgf8I6Eo= @@ -136,6 +148,7 @@ golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= diff --git a/ledger/ledger.go b/ledger/ledger.go index ab43124..e4852e8 100644 --- a/ledger/ledger.go +++ b/ledger/ledger.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "crypto/x509" "fmt" + "os" "time" ledgerPb "github.com/tron-us/go-btfs-common/protos/ledger" @@ -17,35 +18,8 @@ import ( "go.uber.org/zap" ) -var ( - ledgerAddr = "ledger-nginx.bt.co:443" - certFile = `-----BEGIN CERTIFICATE----- -MIIEADCCAuigAwIBAgIBADANBgkqhkiG9w0BAQUFADBjMQswCQYDVQQGEwJVUzEh -MB8GA1UEChMYVGhlIEdvIERhZGR5IEdyb3VwLCBJbmMuMTEwLwYDVQQLEyhHbyBE -YWRkeSBDbGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTA0MDYyOTE3 -MDYyMFoXDTM0MDYyOTE3MDYyMFowYzELMAkGA1UEBhMCVVMxITAfBgNVBAoTGFRo -ZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28gRGFkZHkgQ2xhc3Mg -MiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCCASAwDQYJKoZIhvcNAQEBBQADggEN -ADCCAQgCggEBAN6d1+pXGEmhW+vXX0iG6r7d/+TvZxz0ZWizV3GgXne77ZtJ6XCA -PVYYYwhv2vLM0D9/AlQiVBDYsoHUwHU9S3/Hd8M+eKsaA7Ugay9qK7HFiH7Eux6w -wdhFJ2+qN1j3hybX2C32qRe3H3I2TqYXP2WYktsqbl2i/ojgC95/5Y0V4evLOtXi -EqITLdiOr18SPaAIBQi2XKVlOARFmR6jYGB0xUGlcmIbYsUfb18aQr4CUWWoriMY -avx4A6lNf4DD+qta/KFApMoZFv6yyO9ecw3ud72a9nmYvLEHZ6IVDd2gWMZEewo+ -YihfukEHU1jPEX44dMX4/7VpkI+EdOqXG68CAQOjgcAwgb0wHQYDVR0OBBYEFNLE -sNKR1EwRcbNhyz2h/t2oatTjMIGNBgNVHSMEgYUwgYKAFNLEsNKR1EwRcbNhyz2h -/t2oatTjoWekZTBjMQswCQYDVQQGEwJVUzEhMB8GA1UEChMYVGhlIEdvIERhZGR5 -IEdyb3VwLCBJbmMuMTEwLwYDVQQLEyhHbyBEYWRkeSBDbGFzcyAyIENlcnRpZmlj -YXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQAD -ggEBADJL87LKPpH8EsahB4yOd6AzBhRckB4Y9wimPQoZ+YeAEW5p5JYXMP80kWNy -OO7MHAGjHZQopDH2esRU1/blMVgDoszOYtuURXO1v0XJJLXVggKtI3lpjbi2Tc7P -TMozI+gciKqdi0FuFskg5YmezTvacPd+mSYgFFQlq25zheabIZ0KbIIOqPjCDPoQ -HmyW74cNxA9hi63ugyuV+I6ShHI56yDqg+2DzZduCLzrTia2cyvk0/ZM/iZx4mER -dEr/VxqHD3VILs9RaRegAhJhldXRQLIQTO7ErBBDpqWeCtWVYpoNz4iCxTIM5Cuf -ReYNnyicsbkqWletNw+vHX/bvZ8= ------END CERTIFICATE-----` -) -func LedgerConnection() (*grpc.ClientConn, error) { +func LedgerConnection(ledgerAddr, certFile string) (*grpc.ClientConn, error) { var grpcOption grpc.DialOption if certFile == "" { grpcOption = grpc.WithInsecure() @@ -157,7 +131,7 @@ func CreateChannel(ctx context.Context, ledgerClient ledgerPb.ChannelsClient, ch } func CloseChannel(ctx context.Context, signedChannelState *ledgerPb.SignedChannelState) error { - clientConn, err := LedgerConnection() + clientConn, err := LedgerConnection(os.Getenv("LEDGER_ADDR"), os.Getenv("LEDGER_CERT")) defer CloseConnection(clientConn) if err != nil { return err diff --git a/protos/ledger/ledger.pb.go b/protos/ledger/ledger.pb.go index f54a3d7..c583219 100644 --- a/protos/ledger/ledger.pb.go +++ b/protos/ledger/ledger.pb.go @@ -106,7 +106,6 @@ func (*SignedPublicKey) ProtoMessage() {} func (*SignedPublicKey) Descriptor() ([]byte, []int) { return fileDescriptor_858b35020cfe9185, []int{2} } - func (m *SignedPublicKey) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SignedPublicKey.Unmarshal(m, b) } @@ -298,7 +297,6 @@ func (*SignedCreateAccountResult) ProtoMessage() {} func (*SignedCreateAccountResult) Descriptor() ([]byte, []int) { return fileDescriptor_858b35020cfe9185, []int{6} } - func (m *SignedCreateAccountResult) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SignedCreateAccountResult.Unmarshal(m, b) } From 1a8fdb2b4307e321719b07ac2c8f683c0018f711 Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Mon, 4 Nov 2019 13:41:10 -0800 Subject: [PATCH 5/5] update CloseChannel function --- ledger/ledger.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ledger/ledger.go b/ledger/ledger.go index e4852e8..064d3ee 100644 --- a/ledger/ledger.go +++ b/ledger/ledger.go @@ -130,13 +130,7 @@ func CreateChannel(ctx context.Context, ledgerClient ledgerPb.ChannelsClient, ch }) } -func CloseChannel(ctx context.Context, signedChannelState *ledgerPb.SignedChannelState) error { - clientConn, err := LedgerConnection(os.Getenv("LEDGER_ADDR"), os.Getenv("LEDGER_CERT")) - defer CloseConnection(clientConn) - if err != nil { - return err - } - ledgerClient := NewClient(clientConn) +func CloseChannel(ctx context.Context, ledgerClient ledgerPb.ChannelsClient, signedChannelState *ledgerPb.SignedChannelState) error { _, err = ledgerClient.CloseChannel(ctx, signedChannelState) if err != nil { return err