diff --git a/Gopkg.lock b/Gopkg.lock index b7bd6f4f7..fdcf5a3be 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -18,7 +18,7 @@ version = "v1.4.7" [[projects]] - digest = "1:489a99067cd08971bd9c1ee0055119ba8febc1429f9200ab0bec68d35e8c4833" + digest = "1:b532ee3f683c057e797694b5bfeb3827d89e6adf41c53dbc80e549bca76364ea" name = "github.com/golang/protobuf" packages = [ "jsonpb", @@ -35,8 +35,8 @@ "ptypes/wrappers", ] pruneopts = "UT" - revision = "b5d812f8a3706043e23a9cd5babf2e5423744d30" - version = "v1.3.1" + revision = "6c65a5562fc06764971b7c5d05c76c75e84bdbf7" + version = "v1.3.2" [[projects]] digest = "1:bf40199583e5143d1472fc34d10d6f4b69d97572142acf343b3e43136da40823" @@ -53,7 +53,7 @@ version = "v0.3.0" [[projects]] - digest = "1:d5343c4f76b40152cd27dae5c8248714316ba255bcb05d9dd349809ec388f17a" + digest = "1:07ac748d2913b3c6d963aceec7fc4348c34a4ea58c0063779d08c2717380f7e9" name = "github.com/grpc-ecosystem/grpc-gateway" packages = [ "internal", @@ -61,8 +61,8 @@ "utilities", ] pruneopts = "UT" - revision = "d54b3615f714b03edde6d9206fa0476a9169c966" - version = "v1.9.3" + revision = "bebc7374a79e1105d786ef3468b474e47d652511" + version = "v1.9.4" [[projects]] digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10" @@ -83,6 +83,14 @@ revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241" version = "v1.0.0" +[[projects]] + digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" + name = "github.com/inconshreveable/mousetrap" + packages = ["."] + pruneopts = "UT" + revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" + version = "v1.0" + [[projects]] digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de" name = "github.com/konsorten/go-windows-terminal-sequences" @@ -150,6 +158,14 @@ revision = "8c9545af88b134710ab1cd196795e7f2388358d7" version = "v1.3.0" +[[projects]] + digest = "1:e096613fb7cf34743d49af87d197663cfccd61876e2219853005a57baedfa562" + name = "github.com/spf13/cobra" + packages = ["."] + pruneopts = "UT" + revision = "f2b07da1e2c38d5f12845a4f607e2e1018cbb1f5" + version = "v0.0.5" + [[projects]] digest = "1:1b753ec16506f5864d26a28b43703c58831255059644351bbcb019b843950900" name = "github.com/spf13/jwalterweatherman" @@ -176,11 +192,23 @@ [[projects]] branch = "master" - digest = "1:fcce1a643dc47e06d586f09bee0c55f236435878f348b3ec3537ccfa347b1db0" + digest = "1:6bae001f7c4cddc9ebf2b47bd5ff1bd3978a84b422c468d6037dad284c8c8e9d" + name = "github.com/tyler-smith/go-bip39" + packages = [ + ".", + "wordlists", + ] + pruneopts = "UT" + revision = "dbb3b84ba2ef14e894f5e33d6c6e43641e665738" + +[[projects]] + branch = "master" + digest = "1:6bc5f992ed1dd4346d657b7467f7b3c61b3188607770ee20ab3ad75ab666e3c7" name = "golang.org/x/crypto" packages = [ "ed25519", "ed25519/internal/edwards25519", + "pbkdf2", "sha3", ] pruneopts = "UT" @@ -204,14 +232,14 @@ [[projects]] branch = "master" - digest = "1:6f7b102dfe61016b45aa051b96413e36cc2eff446b61249fdf723dd8e24d308b" + digest = "1:a0e4b2275e7939970d395eb6d03f409378eb586aab72e0a461d95e3435c6c5c4" name = "golang.org/x/sys" packages = [ "cpu", "unix", ] pruneopts = "UT" - revision = "04f50cda93cbb67f2afa353c52f342100e80e625" + revision = "fae7ac547cb717d141c433a2a173315e216b64c4" [[projects]] digest = "1:8d8faad6b12a3a4c819a3f9618cb6ee1fa1cfc33253abeeea8b55336721e3405" @@ -312,7 +340,9 @@ "github.com/grpc-ecosystem/grpc-gateway/utilities", "github.com/mattn/go-sqlite3", "github.com/sirupsen/logrus", + "github.com/spf13/cobra", "github.com/spf13/viper", + "github.com/tyler-smith/go-bip39", "golang.org/x/crypto/ed25519", "golang.org/x/crypto/sha3", "golang.org/x/net/context", diff --git a/Gopkg.toml b/Gopkg.toml index 78d164cb8..a99a61ae4 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -65,3 +65,11 @@ [[constraint]] branch = "master" name = "golang.org/x/crypto" + +[[constraint]] + name = "github.com/spf13/cobra" + version = "0.0.5" + +[[constraint]] + branch = "master" + name = "github.com/tyler-smith/go-bip39" \ No newline at end of file diff --git a/cmd/account/account.go b/cmd/account/account.go new file mode 100644 index 000000000..6269c8bcf --- /dev/null +++ b/cmd/account/account.go @@ -0,0 +1,41 @@ +package account + +import ( + "encoding/hex" + + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/tyler-smith/go-bip39" + "github.com/zoobc/zoobc-core/common/util" +) + +func GenerateAccount(logger *logrus.Logger) *cobra.Command { + var accountCmd = &cobra.Command{ + Use: "account", + Short: "account is a developer cli tools to generate account.", + Long: `account is a developer cli tools to generate account. +running 'zoobc account generate' will show create an account detail with its public key and +private key both in bytes and hex representation + the secret phrase + `, + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + if args[0] == "generate" { + entropy, _ := bip39.NewEntropy(128) + seed, _ := bip39.NewMnemonic(entropy) + privateKey, _ := util.GetPrivateKeyFromSeed(seed) + publicKey := privateKey[32:] + address, _ := util.GetAddressFromPublicKey(publicKey) + logger.Infof("seed: %s", seed) + logger.Infof("public key hex: %s", hex.EncodeToString(publicKey)) + logger.Infof("public key bytes: %v", publicKey) + logger.Infof("private key bytes: %v", privateKey) + logger.Infof("private key hex: %v", hex.EncodeToString(privateKey)) + logger.Infof("address: %s", address) + + } else { + logger.Error("unknown command") + } + }, + } + return accountCmd +} diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 000000000..0323133b7 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "github.com/spf13/cobra" + "github.com/zoobc/zoobc-core/cmd/account" + "github.com/zoobc/zoobc-core/common/util" +) + +func main() { + var rootCmd = &cobra.Command{Use: "zoobc"} + logger, _ := util.InitLogger(".log/", "debug.log") + rootCmd.AddCommand(account.GenerateAccount(logger)) + _ = rootCmd.Execute() +} diff --git a/cmd/readme.md b/cmd/readme.md new file mode 100644 index 000000000..bfc9c59a0 --- /dev/null +++ b/cmd/readme.md @@ -0,0 +1,18 @@ +### Zoobc - CMD + +Command line interface to as a utility tools to develop the zoobc system. + +### Structure + +- main.go -> register all command +- package + - specific.go + - ... +- readme.md + + +### Run + +- `go run main.go {command} {subcommand}` + +- example: `go run main.go account generate` will generate account to use. \ No newline at end of file diff --git a/common/database/migration.go b/common/database/migration.go index 7811b0c46..c3f5a345a 100644 --- a/common/database/migration.go +++ b/common/database/migration.go @@ -49,7 +49,7 @@ func (m *Migration) Init(qe *query.Executor) error { );`, ` CREATE TABLE IF NOT EXISTS "transaction" ( - "id" BLOB, + "id" INTEGER, "block_id" INTEGER, "block_height" INTEGER, "sender_account_id" BLOB, diff --git a/common/model/account.pb.go b/common/model/account.pb.go index 50e2db884..1e97b9026 100644 --- a/common/model/account.pb.go +++ b/common/model/account.pb.go @@ -1,13 +1,11 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: model/account.proto -package model +package model // import "github.com/zoobc/zoobc-core/common/model" -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - math "math" -) +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal @@ -18,12 +16,12 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package // Account represent the transaction data structure stored in the database type Account struct { ID []byte `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` - AccountType int32 `protobuf:"varint,2,opt,name=AccountType,proto3" json:"AccountType,omitempty"` + AccountType uint32 `protobuf:"varint,2,opt,name=AccountType,proto3" json:"AccountType,omitempty"` Address string `protobuf:"bytes,3,opt,name=Address,proto3" json:"Address,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -34,17 +32,16 @@ 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_f61014d6ab0483e9, []int{0} + return fileDescriptor_account_83662a8cb0f99a2a, []int{0} } - func (m *Account) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Account.Unmarshal(m, b) } func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Account.Marshal(b, m, deterministic) } -func (m *Account) XXX_Merge(src proto.Message) { - xxx_messageInfo_Account.Merge(m, src) +func (dst *Account) XXX_Merge(src proto.Message) { + xxx_messageInfo_Account.Merge(dst, src) } func (m *Account) XXX_Size() int { return xxx_messageInfo_Account.Size(m) @@ -62,7 +59,7 @@ func (m *Account) GetID() []byte { return nil } -func (m *Account) GetAccountType() int32 { +func (m *Account) GetAccountType() uint32 { if m != nil { return m.AccountType } @@ -90,17 +87,16 @@ func (m *GetAccountRequest) Reset() { *m = GetAccountRequest{} } func (m *GetAccountRequest) String() string { return proto.CompactTextString(m) } func (*GetAccountRequest) ProtoMessage() {} func (*GetAccountRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f61014d6ab0483e9, []int{1} + return fileDescriptor_account_83662a8cb0f99a2a, []int{1} } - func (m *GetAccountRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetAccountRequest.Unmarshal(m, b) } func (m *GetAccountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_GetAccountRequest.Marshal(b, m, deterministic) } -func (m *GetAccountRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetAccountRequest.Merge(m, src) +func (dst *GetAccountRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetAccountRequest.Merge(dst, src) } func (m *GetAccountRequest) XXX_Size() int { return xxx_messageInfo_GetAccountRequest.Size(m) @@ -137,17 +133,16 @@ func (m *GetAccountsRequest) Reset() { *m = GetAccountsRequest{} } func (m *GetAccountsRequest) String() string { return proto.CompactTextString(m) } func (*GetAccountsRequest) ProtoMessage() {} func (*GetAccountsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f61014d6ab0483e9, []int{2} + return fileDescriptor_account_83662a8cb0f99a2a, []int{2} } - func (m *GetAccountsRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetAccountsRequest.Unmarshal(m, b) } func (m *GetAccountsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_GetAccountsRequest.Marshal(b, m, deterministic) } -func (m *GetAccountsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetAccountsRequest.Merge(m, src) +func (dst *GetAccountsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetAccountsRequest.Merge(dst, src) } func (m *GetAccountsRequest) XXX_Size() int { return xxx_messageInfo_GetAccountsRequest.Size(m) @@ -179,17 +174,16 @@ func (m *GetAccountsResponse) Reset() { *m = GetAccountsResponse{} } func (m *GetAccountsResponse) String() string { return proto.CompactTextString(m) } func (*GetAccountsResponse) ProtoMessage() {} func (*GetAccountsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f61014d6ab0483e9, []int{3} + return fileDescriptor_account_83662a8cb0f99a2a, []int{3} } - func (m *GetAccountsResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetAccountsResponse.Unmarshal(m, b) } func (m *GetAccountsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_GetAccountsResponse.Marshal(b, m, deterministic) } -func (m *GetAccountsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetAccountsResponse.Merge(m, src) +func (dst *GetAccountsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetAccountsResponse.Merge(dst, src) } func (m *GetAccountsResponse) XXX_Size() int { return xxx_messageInfo_GetAccountsResponse.Size(m) @@ -221,23 +215,23 @@ func init() { proto.RegisterType((*GetAccountsResponse)(nil), "model.GetAccountsResponse") } -func init() { proto.RegisterFile("model/account.proto", fileDescriptor_f61014d6ab0483e9) } - -var fileDescriptor_f61014d6ab0483e9 = []byte{ - // 236 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xb1, 0x4b, 0x03, 0x31, - 0x14, 0xc6, 0xb9, 0x94, 0x5a, 0x7c, 0xb5, 0x05, 0xd3, 0x25, 0x63, 0xb8, 0x29, 0x08, 0x5e, 0x40, - 0xc1, 0xcd, 0xa1, 0x52, 0x90, 0xae, 0x51, 0x17, 0xb7, 0x5e, 0xee, 0xa1, 0x05, 0x73, 0xef, 0xbc, - 0xe4, 0x06, 0xfb, 0xd7, 0x0b, 0xe9, 0xa5, 0xa6, 0xe0, 0x12, 0xc8, 0xef, 0xe5, 0xc7, 0xfb, 0xf2, - 0xc1, 0xca, 0x51, 0x83, 0x5f, 0x7a, 0x67, 0x2d, 0x0d, 0x6d, 0xa8, 0xba, 0x9e, 0x02, 0xf1, 0x69, - 0x84, 0xe5, 0x1b, 0xcc, 0xd6, 0x47, 0xce, 0x97, 0xc0, 0xb6, 0x1b, 0x51, 0xc8, 0x42, 0x5d, 0x19, - 0xb6, 0xdd, 0x70, 0x09, 0xf3, 0x71, 0xf4, 0xfa, 0xd3, 0xa1, 0x60, 0xb2, 0x50, 0x53, 0x93, 0x23, - 0x2e, 0x60, 0xb6, 0x6e, 0x9a, 0x1e, 0xbd, 0x17, 0x13, 0x59, 0xa8, 0x4b, 0x93, 0xae, 0xe5, 0x23, - 0x5c, 0x3f, 0x63, 0x18, 0xdf, 0x1a, 0xfc, 0x1e, 0xd0, 0xe7, 0x0b, 0x16, 0x71, 0x41, 0xa6, 0xb3, - 0x08, 0x4f, 0xfa, 0x03, 0xf0, 0x3f, 0xdd, 0x27, 0xff, 0x9f, 0x40, 0x8b, 0xb3, 0x40, 0xe5, 0x0e, - 0x56, 0x67, 0x9e, 0xef, 0xa8, 0xf5, 0x98, 0x89, 0x2f, 0xfb, 0x03, 0x8e, 0x09, 0x72, 0xc4, 0xd5, - 0xa9, 0x06, 0xc1, 0xe4, 0x44, 0xcd, 0xef, 0x96, 0x55, 0xec, 0xa7, 0x4a, 0x5f, 0x48, 0xe3, 0xa7, - 0x9b, 0x77, 0xf5, 0xb1, 0x0f, 0x9f, 0x43, 0x5d, 0x59, 0x72, 0xfa, 0x40, 0x54, 0xdb, 0xe3, 0x79, - 0x6b, 0xa9, 0x47, 0x6d, 0xc9, 0x39, 0x6a, 0x75, 0x94, 0xeb, 0x8b, 0x58, 0xf5, 0xfd, 0x6f, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x36, 0xeb, 0xf9, 0xaa, 0x81, 0x01, 0x00, 0x00, +func init() { proto.RegisterFile("model/account.proto", fileDescriptor_account_83662a8cb0f99a2a) } + +var fileDescriptor_account_83662a8cb0f99a2a = []byte{ + // 233 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xce, 0xcd, 0x4f, 0x49, + 0xcd, 0xd1, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x62, 0x05, 0x0b, 0x2a, 0x85, 0x72, 0xb1, 0x3b, 0x42, 0xc4, 0x85, 0xf8, 0xb8, 0x98, 0x3c, 0x5d, + 0x24, 0x18, 0x15, 0x18, 0x35, 0x78, 0x82, 0x98, 0x3c, 0x5d, 0x84, 0x14, 0xb8, 0xb8, 0xa1, 0x52, + 0x21, 0x95, 0x05, 0xa9, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xbc, 0x41, 0xc8, 0x42, 0x42, 0x12, 0x5c, + 0xec, 0x8e, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, 0x12, 0xcc, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x30, + 0xae, 0x92, 0x2d, 0x97, 0xa0, 0x7b, 0x6a, 0x09, 0x54, 0x6d, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x31, + 0xb2, 0x05, 0xbc, 0x60, 0x0b, 0x90, 0xb4, 0x43, 0x0c, 0x87, 0x6b, 0x37, 0xe3, 0x12, 0x42, 0x68, + 0x2f, 0x86, 0xe9, 0x27, 0xe8, 0x20, 0xa5, 0x44, 0x2e, 0x61, 0x14, 0x7d, 0xc5, 0x05, 0xf9, 0x79, + 0xc5, 0xa9, 0x48, 0x1a, 0x83, 0x33, 0xab, 0x52, 0xa1, 0x2e, 0x40, 0x16, 0x12, 0xd2, 0x80, 0x07, + 0x83, 0x04, 0x93, 0x02, 0xb3, 0x06, 0xb7, 0x11, 0x9f, 0x1e, 0x38, 0x7c, 0xf4, 0x60, 0x5e, 0x80, + 0x49, 0x3b, 0x69, 0x45, 0x69, 0xa4, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, + 0x57, 0xe5, 0xe7, 0x27, 0x25, 0x43, 0x48, 0xdd, 0xe4, 0xfc, 0xa2, 0x54, 0xfd, 0xe4, 0xfc, 0xdc, + 0xdc, 0xfc, 0x3c, 0x7d, 0xb0, 0xe6, 0x24, 0x36, 0x70, 0x50, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, + 0xff, 0x5a, 0xe7, 0x84, 0x7d, 0x81, 0x01, 0x00, 0x00, } diff --git a/common/model/transaction.pb.go b/common/model/transaction.pb.go index 5eae15216..a758f2916 100644 --- a/common/model/transaction.pb.go +++ b/common/model/transaction.pb.go @@ -20,24 +20,27 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package // Transaction represent the transaction data structure stored in the database type Transaction struct { - ID []byte `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` - BlockID int64 `protobuf:"varint,2,opt,name=BlockID,proto3" json:"BlockID,omitempty"` - Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` - SenderAccountID []byte `protobuf:"bytes,4,opt,name=SenderAccountID,proto3" json:"SenderAccountID,omitempty"` - RecipientAccountID []byte `protobuf:"bytes,5,opt,name=RecipientAccountID,proto3" json:"RecipientAccountID,omitempty"` - TransactionType uint32 `protobuf:"varint,6,opt,name=TransactionType,proto3" json:"TransactionType,omitempty"` - Fee int64 `protobuf:"varint,7,opt,name=Fee,proto3" json:"Fee,omitempty"` - Timestamp int64 `protobuf:"varint,8,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` - TransactionHash []byte `protobuf:"bytes,9,opt,name=TransactionHash,proto3" json:"TransactionHash,omitempty"` - TransactionBodyLength uint32 `protobuf:"varint,10,opt,name=TransactionBodyLength,proto3" json:"TransactionBodyLength,omitempty"` - TransactionBodyBytes []byte `protobuf:"bytes,11,opt,name=TransactionBodyBytes,proto3" json:"TransactionBodyBytes,omitempty"` - Signature []byte `protobuf:"bytes,12,opt,name=Signature,proto3" json:"Signature,omitempty"` + Version uint32 `protobuf:"varint,1,opt,name=Version,proto3" json:"Version,omitempty"` + ID int64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` + BlockID int64 `protobuf:"varint,3,opt,name=BlockID,proto3" json:"BlockID,omitempty"` + Height uint32 `protobuf:"varint,4,opt,name=Height,proto3" json:"Height,omitempty"` + SenderAccountType uint32 `protobuf:"varint,5,opt,name=SenderAccountType,proto3" json:"SenderAccountType,omitempty"` + SenderAccountAddress string `protobuf:"bytes,6,opt,name=SenderAccountAddress,proto3" json:"SenderAccountAddress,omitempty"` + RecipientAccountType uint32 `protobuf:"varint,7,opt,name=RecipientAccountType,proto3" json:"RecipientAccountType,omitempty"` + RecipientAccountAddress string `protobuf:"bytes,8,opt,name=RecipientAccountAddress,proto3" json:"RecipientAccountAddress,omitempty"` + TransactionType uint32 `protobuf:"varint,9,opt,name=TransactionType,proto3" json:"TransactionType,omitempty"` + Fee int64 `protobuf:"varint,10,opt,name=Fee,proto3" json:"Fee,omitempty"` + Timestamp int64 `protobuf:"varint,11,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` + TransactionHash []byte `protobuf:"bytes,12,opt,name=TransactionHash,proto3" json:"TransactionHash,omitempty"` + TransactionBodyLength uint32 `protobuf:"varint,13,opt,name=TransactionBodyLength,proto3" json:"TransactionBodyLength,omitempty"` + TransactionBodyBytes []byte `protobuf:"bytes,14,opt,name=TransactionBodyBytes,proto3" json:"TransactionBodyBytes,omitempty"` // TransactionBody // // Types that are valid to be assigned to TransactionBody: // *Transaction_EmptyTransactionBody // *Transaction_SendMoneyTransactionBody TransactionBody isTransaction_TransactionBody `protobuf_oneof:"TransactionBody"` + Signature []byte `protobuf:"bytes,17,opt,name=Signature,proto3" json:"Signature,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -47,7 +50,7 @@ func (m *Transaction) Reset() { *m = Transaction{} } func (m *Transaction) String() string { return proto.CompactTextString(m) } func (*Transaction) ProtoMessage() {} func (*Transaction) Descriptor() ([]byte, []int) { - return fileDescriptor_transaction_ceceb700b544e8c6, []int{0} + return fileDescriptor_transaction_89ae06b0ecfafee0, []int{0} } func (m *Transaction) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Transaction.Unmarshal(m, b) @@ -67,11 +70,18 @@ func (m *Transaction) XXX_DiscardUnknown() { var xxx_messageInfo_Transaction proto.InternalMessageInfo -func (m *Transaction) GetID() []byte { +func (m *Transaction) GetVersion() uint32 { + if m != nil { + return m.Version + } + return 0 +} + +func (m *Transaction) GetID() int64 { if m != nil { return m.ID } - return nil + return 0 } func (m *Transaction) GetBlockID() int64 { @@ -88,18 +98,32 @@ func (m *Transaction) GetHeight() uint32 { return 0 } -func (m *Transaction) GetSenderAccountID() []byte { +func (m *Transaction) GetSenderAccountType() uint32 { if m != nil { - return m.SenderAccountID + return m.SenderAccountType } - return nil + return 0 } -func (m *Transaction) GetRecipientAccountID() []byte { +func (m *Transaction) GetSenderAccountAddress() string { if m != nil { - return m.RecipientAccountID + return m.SenderAccountAddress } - return nil + return "" +} + +func (m *Transaction) GetRecipientAccountType() uint32 { + if m != nil { + return m.RecipientAccountType + } + return 0 +} + +func (m *Transaction) GetRecipientAccountAddress() string { + if m != nil { + return m.RecipientAccountAddress + } + return "" } func (m *Transaction) GetTransactionType() uint32 { @@ -144,23 +168,16 @@ func (m *Transaction) GetTransactionBodyBytes() []byte { return nil } -func (m *Transaction) GetSignature() []byte { - if m != nil { - return m.Signature - } - return nil -} - type isTransaction_TransactionBody interface { isTransaction_TransactionBody() } type Transaction_EmptyTransactionBody struct { - EmptyTransactionBody *EmptyTransactionBody `protobuf:"bytes,13,opt,name=emptyTransactionBody,proto3,oneof"` + EmptyTransactionBody *EmptyTransactionBody `protobuf:"bytes,15,opt,name=emptyTransactionBody,proto3,oneof"` } type Transaction_SendMoneyTransactionBody struct { - SendMoneyTransactionBody *SendMoneyTransactionBody `protobuf:"bytes,14,opt,name=sendMoneyTransactionBody,proto3,oneof"` + SendMoneyTransactionBody *SendMoneyTransactionBody `protobuf:"bytes,16,opt,name=sendMoneyTransactionBody,proto3,oneof"` } func (*Transaction_EmptyTransactionBody) isTransaction_TransactionBody() {} @@ -188,6 +205,13 @@ func (m *Transaction) GetSendMoneyTransactionBody() *SendMoneyTransactionBody { return nil } +func (m *Transaction) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + // XXX_OneofFuncs is for the internal use of the proto package. func (*Transaction) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { return _Transaction_OneofMarshaler, _Transaction_OneofUnmarshaler, _Transaction_OneofSizer, []interface{}{ @@ -201,12 +225,12 @@ func _Transaction_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { // TransactionBody switch x := m.TransactionBody.(type) { case *Transaction_EmptyTransactionBody: - b.EncodeVarint(13<<3 | proto.WireBytes) + b.EncodeVarint(15<<3 | proto.WireBytes) if err := b.EncodeMessage(x.EmptyTransactionBody); err != nil { return err } case *Transaction_SendMoneyTransactionBody: - b.EncodeVarint(14<<3 | proto.WireBytes) + b.EncodeVarint(16<<3 | proto.WireBytes) if err := b.EncodeMessage(x.SendMoneyTransactionBody); err != nil { return err } @@ -220,7 +244,7 @@ func _Transaction_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { func _Transaction_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { m := msg.(*Transaction) switch tag { - case 13: // TransactionBody.emptyTransactionBody + case 15: // TransactionBody.emptyTransactionBody if wire != proto.WireBytes { return true, proto.ErrInternalBadWireType } @@ -228,7 +252,7 @@ func _Transaction_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Bu err := b.DecodeMessage(msg) m.TransactionBody = &Transaction_EmptyTransactionBody{msg} return true, err - case 14: // TransactionBody.sendMoneyTransactionBody + case 16: // TransactionBody.sendMoneyTransactionBody if wire != proto.WireBytes { return true, proto.ErrInternalBadWireType } @@ -252,7 +276,7 @@ func _Transaction_OneofSizer(msg proto.Message) (n int) { n += s case *Transaction_SendMoneyTransactionBody: s := proto.Size(x.SendMoneyTransactionBody) - n += 1 // tag and wire + n += 2 // tag and wire n += proto.SizeVarint(uint64(s)) n += s case nil: @@ -272,7 +296,7 @@ func (m *EmptyTransactionBody) Reset() { *m = EmptyTransactionBody{} } func (m *EmptyTransactionBody) String() string { return proto.CompactTextString(m) } func (*EmptyTransactionBody) ProtoMessage() {} func (*EmptyTransactionBody) Descriptor() ([]byte, []int) { - return fileDescriptor_transaction_ceceb700b544e8c6, []int{1} + return fileDescriptor_transaction_89ae06b0ecfafee0, []int{1} } func (m *EmptyTransactionBody) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_EmptyTransactionBody.Unmarshal(m, b) @@ -303,7 +327,7 @@ func (m *SendMoneyTransactionBody) Reset() { *m = SendMoneyTransactionBo func (m *SendMoneyTransactionBody) String() string { return proto.CompactTextString(m) } func (*SendMoneyTransactionBody) ProtoMessage() {} func (*SendMoneyTransactionBody) Descriptor() ([]byte, []int) { - return fileDescriptor_transaction_ceceb700b544e8c6, []int{2} + return fileDescriptor_transaction_89ae06b0ecfafee0, []int{2} } func (m *SendMoneyTransactionBody) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SendMoneyTransactionBody.Unmarshal(m, b) @@ -346,7 +370,7 @@ func (m *GetTransactionRequest) Reset() { *m = GetTransactionRequest{} } func (m *GetTransactionRequest) String() string { return proto.CompactTextString(m) } func (*GetTransactionRequest) ProtoMessage() {} func (*GetTransactionRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_transaction_ceceb700b544e8c6, []int{3} + return fileDescriptor_transaction_89ae06b0ecfafee0, []int{3} } func (m *GetTransactionRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetTransactionRequest.Unmarshal(m, b) @@ -409,7 +433,7 @@ func (m *GetTransactionsRequest) Reset() { *m = GetTransactionsRequest{} func (m *GetTransactionsRequest) String() string { return proto.CompactTextString(m) } func (*GetTransactionsRequest) ProtoMessage() {} func (*GetTransactionsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_transaction_ceceb700b544e8c6, []int{4} + return fileDescriptor_transaction_89ae06b0ecfafee0, []int{4} } func (m *GetTransactionsRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetTransactionsRequest.Unmarshal(m, b) @@ -485,7 +509,7 @@ func (m *GetTransactionsResponse) Reset() { *m = GetTransactionsResponse func (m *GetTransactionsResponse) String() string { return proto.CompactTextString(m) } func (*GetTransactionsResponse) ProtoMessage() {} func (*GetTransactionsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_transaction_ceceb700b544e8c6, []int{5} + return fileDescriptor_transaction_89ae06b0ecfafee0, []int{5} } func (m *GetTransactionsResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetTransactionsResponse.Unmarshal(m, b) @@ -529,41 +553,45 @@ func init() { } func init() { - proto.RegisterFile("model/transaction.proto", fileDescriptor_transaction_ceceb700b544e8c6) -} - -var fileDescriptor_transaction_ceceb700b544e8c6 = []byte{ - // 507 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x41, 0x8f, 0xd2, 0x50, - 0x10, 0xde, 0x52, 0x60, 0x97, 0x01, 0x56, 0x7d, 0x61, 0xd9, 0x17, 0x35, 0xda, 0xf4, 0xd4, 0x98, - 0x58, 0x12, 0x34, 0xde, 0xb7, 0xc1, 0x15, 0x12, 0x3d, 0x58, 0x38, 0x99, 0x78, 0x28, 0x65, 0x02, - 0x8d, 0xdb, 0x37, 0xb5, 0x7d, 0x1c, 0x58, 0xff, 0xb4, 0x67, 0x4f, 0xa6, 0x8f, 0xae, 0x7d, 0x94, - 0x72, 0x30, 0x7b, 0x69, 0x3a, 0xdf, 0xcc, 0xfb, 0x66, 0x3a, 0xef, 0xfb, 0x0a, 0xd7, 0x31, 0xad, - 0xf0, 0x6e, 0x24, 0xd3, 0x40, 0x64, 0x41, 0x28, 0x23, 0x12, 0x6e, 0x92, 0x92, 0x24, 0xd6, 0x52, - 0x09, 0xfb, 0x4f, 0x13, 0xba, 0x8b, 0x32, 0xc9, 0x2e, 0xa1, 0x31, 0x9b, 0x70, 0xc3, 0x32, 0x9c, - 0x9e, 0xdf, 0x98, 0x4d, 0x18, 0x87, 0x73, 0xef, 0x8e, 0xc2, 0x1f, 0xb3, 0x09, 0x6f, 0x58, 0x86, - 0x63, 0xfa, 0x0f, 0x21, 0x1b, 0x42, 0x7b, 0x8a, 0xd1, 0x7a, 0x23, 0xb9, 0x69, 0x19, 0x4e, 0xdf, - 0x2f, 0x22, 0xe6, 0xc0, 0x93, 0x39, 0x8a, 0x15, 0xa6, 0x37, 0x61, 0x48, 0x5b, 0x21, 0x67, 0x13, - 0xde, 0x54, 0x74, 0x55, 0x98, 0xb9, 0xc0, 0x7c, 0x0c, 0xa3, 0x24, 0x42, 0x21, 0xcb, 0xe2, 0x96, - 0x2a, 0xae, 0xc9, 0xe4, 0xcc, 0xda, 0xa8, 0x8b, 0x5d, 0x82, 0xbc, 0xad, 0x5a, 0x57, 0x61, 0xf6, - 0x14, 0xcc, 0x5b, 0x44, 0x7e, 0xae, 0x26, 0xce, 0x5f, 0xd9, 0x4b, 0xe8, 0x2c, 0xa2, 0x18, 0x33, - 0x19, 0xc4, 0x09, 0xbf, 0x50, 0x78, 0x09, 0x54, 0x98, 0xa7, 0x41, 0xb6, 0xe1, 0x9d, 0xfd, 0xcc, - 0x15, 0x98, 0xbd, 0x87, 0x2b, 0x0d, 0xf2, 0x68, 0xb5, 0xfb, 0x8c, 0x62, 0x2d, 0x37, 0x1c, 0xd4, - 0x24, 0xf5, 0x49, 0x36, 0x86, 0x41, 0x25, 0xe1, 0xed, 0x24, 0x66, 0xbc, 0xab, 0x9a, 0xd4, 0xe6, - 0xf2, 0x89, 0xe7, 0xd1, 0x5a, 0x04, 0x72, 0x9b, 0x22, 0xef, 0xa9, 0xc2, 0x12, 0x60, 0x5f, 0x61, - 0x80, 0x71, 0x22, 0x77, 0x95, 0xa3, 0xbc, 0x6f, 0x19, 0x4e, 0x77, 0xfc, 0xc2, 0x55, 0xb7, 0xeb, - 0x7e, 0xac, 0x29, 0x99, 0x9e, 0xf9, 0xb5, 0x47, 0xd9, 0x77, 0xe0, 0x19, 0x8a, 0xd5, 0x17, 0x12, - 0x78, 0x44, 0x7b, 0xa9, 0x68, 0x5f, 0x17, 0xb4, 0xf3, 0x13, 0x65, 0xd3, 0x33, 0xff, 0x24, 0x85, - 0xf7, 0xec, 0x60, 0xc7, 0x39, 0x64, 0x0f, 0x61, 0x50, 0x37, 0xa1, 0x3d, 0x06, 0x7e, 0xaa, 0x45, - 0x2e, 0xbb, 0x9b, 0x38, 0x17, 0x84, 0x12, 0xa9, 0xe9, 0x17, 0x91, 0x4d, 0x70, 0xf5, 0x09, 0xa5, - 0x56, 0xed, 0xe3, 0xcf, 0x2d, 0x66, 0x52, 0x53, 0x74, 0x5f, 0x29, 0xfa, 0x60, 0xaf, 0x4d, 0x05, - 0x6b, 0x7b, 0xad, 0x51, 0x42, 0xeb, 0x48, 0x63, 0x39, 0x6c, 0xff, 0x36, 0x60, 0x78, 0xd8, 0x31, - 0x7b, 0x68, 0x59, 0x5a, 0xa3, 0x98, 0xb1, 0xb0, 0xc6, 0x2b, 0x80, 0xdb, 0x94, 0xe2, 0x22, 0xb7, - 0xf7, 0x93, 0x86, 0xb0, 0xe7, 0x70, 0xb1, 0x20, 0xcd, 0x54, 0xa6, 0xff, 0x2f, 0x3e, 0x65, 0xab, - 0xce, 0xff, 0xd8, 0xaa, 0xf3, 0x38, 0x5b, 0xd9, 0xbf, 0xe0, 0xfa, 0xe8, 0x8b, 0xb3, 0x84, 0x44, - 0x56, 0xdd, 0xdb, 0x3c, 0xba, 0xc7, 0x62, 0xe5, 0x55, 0x98, 0x7d, 0x80, 0x9e, 0xce, 0xc0, 0x1b, - 0x96, 0xe9, 0x74, 0xc7, 0xac, 0x90, 0x96, 0x7e, 0x81, 0x07, 0x75, 0xde, 0x9b, 0x6f, 0xce, 0x3a, - 0x92, 0x9b, 0xed, 0xd2, 0x0d, 0x29, 0x1e, 0xdd, 0x13, 0x2d, 0xc3, 0xfd, 0xf3, 0x6d, 0x48, 0x29, - 0x8e, 0x42, 0x8a, 0x63, 0x12, 0x23, 0xc5, 0xb2, 0x6c, 0xab, 0x7f, 0xdc, 0xbb, 0xbf, 0x01, 0x00, - 0x00, 0xff, 0xff, 0x9b, 0x0a, 0x8f, 0x0c, 0xfe, 0x04, 0x00, 0x00, + proto.RegisterFile("model/transaction.proto", fileDescriptor_transaction_89ae06b0ecfafee0) +} + +var fileDescriptor_transaction_89ae06b0ecfafee0 = []byte{ + // 566 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x54, 0xdf, 0x8f, 0xd2, 0x40, + 0x10, 0xbe, 0x82, 0xc7, 0x1d, 0x03, 0xf7, 0x83, 0x0d, 0x07, 0x1b, 0x35, 0xda, 0xf4, 0xa9, 0x31, + 0x0a, 0x09, 0x1a, 0xe3, 0x2b, 0x04, 0x4f, 0x48, 0xf4, 0xc1, 0x85, 0xf8, 0x60, 0xe2, 0x03, 0xb4, + 0x13, 0x68, 0xbc, 0xee, 0xd6, 0xee, 0xf2, 0xc0, 0xf9, 0x1f, 0xf8, 0xd7, 0xfa, 0x27, 0x98, 0x5d, + 0x8a, 0xb4, 0x65, 0x79, 0x69, 0x3a, 0xdf, 0x37, 0x3b, 0xdf, 0xec, 0x74, 0xbe, 0x42, 0x37, 0x16, + 0x21, 0x3e, 0xf4, 0x55, 0xba, 0xe0, 0x72, 0x11, 0xa8, 0x48, 0xf0, 0x5e, 0x92, 0x0a, 0x25, 0xc8, + 0xb9, 0x21, 0xbc, 0x3f, 0x35, 0x68, 0xcc, 0x0f, 0x24, 0xa1, 0x70, 0xf1, 0x0d, 0x53, 0x19, 0x09, + 0x4e, 0x1d, 0xd7, 0xf1, 0xaf, 0xd8, 0x3e, 0x24, 0xd7, 0x50, 0x99, 0x8e, 0x69, 0xc5, 0x75, 0xfc, + 0x2a, 0xab, 0x4c, 0xc7, 0x3a, 0x73, 0xf4, 0x20, 0x82, 0x9f, 0xd3, 0x31, 0xad, 0x1a, 0x70, 0x1f, + 0x92, 0x0e, 0xd4, 0x26, 0x18, 0xad, 0xd6, 0x8a, 0x3e, 0x31, 0x25, 0xb2, 0x88, 0xbc, 0x86, 0xd6, + 0x0c, 0x79, 0x88, 0xe9, 0x30, 0x08, 0xc4, 0x86, 0xab, 0xf9, 0x36, 0x41, 0x7a, 0x6e, 0x52, 0x8e, + 0x09, 0x32, 0x80, 0x76, 0x01, 0x1c, 0x86, 0x61, 0x8a, 0x52, 0xd2, 0x9a, 0xeb, 0xf8, 0x75, 0x66, + 0xe5, 0xf4, 0x19, 0x86, 0x41, 0x94, 0x44, 0xc8, 0x55, 0x5e, 0xe4, 0xc2, 0x88, 0x58, 0x39, 0xf2, + 0x01, 0xba, 0x65, 0x7c, 0x2f, 0x75, 0x69, 0xa4, 0x4e, 0xd1, 0xc4, 0x87, 0x9b, 0xdc, 0xe8, 0x8c, + 0x50, 0xdd, 0x08, 0x95, 0x61, 0x72, 0x0b, 0xd5, 0x7b, 0x44, 0x0a, 0x66, 0x4e, 0xfa, 0x95, 0x3c, + 0x87, 0xfa, 0x3c, 0x8a, 0x51, 0xaa, 0x45, 0x9c, 0xd0, 0x86, 0xc1, 0x0f, 0x40, 0xa9, 0xf2, 0x64, + 0x21, 0xd7, 0xb4, 0xe9, 0x3a, 0x7e, 0x93, 0x95, 0x61, 0xf2, 0x0e, 0xee, 0x72, 0xd0, 0x48, 0x84, + 0xdb, 0xcf, 0xc8, 0x57, 0x6a, 0x4d, 0xaf, 0x4c, 0x27, 0x76, 0x52, 0xcf, 0xa9, 0x44, 0x8c, 0xb6, + 0x0a, 0x25, 0xbd, 0x36, 0x22, 0x56, 0x8e, 0x7c, 0x85, 0x36, 0xc6, 0x89, 0xda, 0x96, 0x48, 0x7a, + 0xe3, 0x3a, 0x7e, 0x63, 0xf0, 0xac, 0x67, 0xf6, 0xa9, 0xf7, 0xd1, 0x92, 0x32, 0x39, 0x63, 0xd6, + 0xa3, 0xe4, 0x07, 0x50, 0x89, 0x3c, 0xfc, 0x22, 0x38, 0x1e, 0x95, 0xbd, 0x35, 0x65, 0x5f, 0x66, + 0x65, 0x67, 0x27, 0xd2, 0x26, 0x67, 0xec, 0x64, 0x09, 0x3d, 0xe3, 0x59, 0xb4, 0xe2, 0x0b, 0xb5, + 0x49, 0x91, 0xb6, 0xcc, 0xd5, 0x0e, 0xc0, 0xa8, 0x55, 0x98, 0xb1, 0x3e, 0xe0, 0x75, 0xa0, 0x6d, + 0xeb, 0xdf, 0x1b, 0x00, 0x3d, 0xd5, 0x80, 0x5e, 0xf6, 0x61, 0xac, 0xb7, 0xc2, 0xf8, 0xa5, 0xca, + 0xb2, 0xc8, 0x13, 0x70, 0xf7, 0x09, 0x55, 0x2e, 0x9b, 0xe1, 0xaf, 0x0d, 0x4a, 0x95, 0xf9, 0x68, + 0x67, 0x2e, 0xed, 0xa3, 0x42, 0x97, 0x3b, 0xc3, 0x1c, 0x00, 0xdb, 0x26, 0x9c, 0x1f, 0xed, 0x98, + 0x86, 0xbd, 0xbf, 0x0e, 0x74, 0x8a, 0x8a, 0x72, 0x2f, 0x79, 0x30, 0x64, 0xd6, 0x63, 0x66, 0xc8, + 0x17, 0x00, 0xf7, 0xa9, 0x88, 0x33, 0x6e, 0x67, 0xed, 0x1c, 0x42, 0x9e, 0xc2, 0xe5, 0x5c, 0x64, + 0xec, 0xce, 0xe3, 0xff, 0x63, 0xdd, 0x58, 0xc1, 0x82, 0xd3, 0xb1, 0x69, 0xbe, 0xce, 0xca, 0x30, + 0xe9, 0x01, 0x29, 0x3b, 0x68, 0x3a, 0x36, 0xb7, 0xa8, 0x33, 0x0b, 0x63, 0xb3, 0x55, 0xcd, 0x6a, + 0x2b, 0xef, 0x37, 0x74, 0x8f, 0x6e, 0x2c, 0x13, 0xc1, 0x65, 0x79, 0x6e, 0xb3, 0xe8, 0x11, 0xb3, + 0x91, 0x97, 0x61, 0xf2, 0x1e, 0x9a, 0xf9, 0x0a, 0xb4, 0xe2, 0x56, 0xfd, 0xc6, 0x80, 0x64, 0x8b, + 0x97, 0xff, 0x80, 0x85, 0xbc, 0xd1, 0xab, 0xef, 0xfe, 0x2a, 0x52, 0xeb, 0xcd, 0xb2, 0x17, 0x88, + 0xb8, 0xff, 0x28, 0xc4, 0x32, 0xd8, 0x3d, 0xdf, 0x04, 0x22, 0xc5, 0x7e, 0x20, 0xe2, 0x58, 0xf0, + 0xbe, 0xa9, 0xb2, 0xac, 0x99, 0x7f, 0xee, 0xdb, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x4c, 0x86, + 0x6a, 0x7c, 0x8e, 0x05, 0x00, 0x00, } diff --git a/common/schema b/common/schema index 5e47fe998..5ef34ea7a 160000 --- a/common/schema +++ b/common/schema @@ -1 +1 @@ -Subproject commit 5e47fe998303adf452e3d28425cee25e0d547c74 +Subproject commit 5ef34ea7ad528e4bf91655a7be468d6887ff987b diff --git a/common/util/account.go b/common/util/account.go index 03699887e..8ed45f5ee 100644 --- a/common/util/account.go +++ b/common/util/account.go @@ -3,32 +3,63 @@ package util import ( "encoding/base64" "encoding/binary" + "errors" + + "golang.org/x/crypto/ed25519" "golang.org/x/crypto/sha3" ) // GetAccountIDByPublicKey return the account ID byte which is the hash of -// account type (int32) and the account address (default: base64(public key)) +// account type (uint32) and the account address (default: base64(public key)) // for type 0 -func GetAccountIDByPublicKey(accountType int32, publicKey []byte) []byte { +func GetAccountIDByPublicKey(accountType uint32, publicKey []byte) []byte { accountTypeByte := make([]byte, 4) - binary.LittleEndian.PutUint32(accountTypeByte, uint32(accountType)) + binary.LittleEndian.PutUint32(accountTypeByte, accountType) var address string if accountType == 0 { // default account type: zoobc - rawAddress := make([]byte, 33) - copy(rawAddress, publicKey) - - // Add Checksum Byte to end - rawAddress[32] = GetChecksumByte(publicKey) - address = base64.URLEncoding.EncodeToString(publicKey) + address, _ = GetAddressFromPublicKey(publicKey) } digest := sha3.New256() - _, _ = digest.Write(accountTypeByte) + _, _ = digest.Write(accountTypeByte[:2]) _, _ = digest.Write([]byte(address)) accountID := digest.Sum([]byte{}) return accountID } +// GetPrivateKeyFromSeed Get the raw private key corresponding to a seed (secret phrase) +func GetPrivateKeyFromSeed(seed string) ([]byte, error) { + // Convert seed (secret phrase) to byte array + seedBuffer := []byte(seed) + + // Compute SHA3-256 hash of seed (secret phrase) + seedHash := sha3.Sum256(seedBuffer) + + // Generate a private key from the hash of the seed + privateKey := ed25519.NewKeyFromSeed(seedHash[:]) + + return privateKey, nil +} + +// GetAddressFromPublicKey Get the formatted address from a raw public key +func GetAddressFromPublicKey(publicKey []byte) (string, error) { + // public key should be 32 long + if len(publicKey) != 32 { + return "", errors.New("ErrInvalidPublicKeyLength") + } + // Make 33 byte buffer for Public Key + Checksum Byte + rawAddress := make([]byte, 33) + copy(rawAddress, publicKey) + + // Add Checksum Byte to end + rawAddress[32] = GetChecksumByte(publicKey) + + // Convert the raw address (public key + checksum) to Base64 notation + address := base64.URLEncoding.EncodeToString(rawAddress) + + return address, nil +} + // GetChecksumByte Calculate a checksum byte from a collection of bytes // checksum 255 = 255, 256 = 0, 257 = 1 and so on. func GetChecksumByte(bytes []byte) byte { diff --git a/common/util/account_test.go b/common/util/account_test.go index 98d55ae5b..878753224 100644 --- a/common/util/account_test.go +++ b/common/util/account_test.go @@ -7,7 +7,7 @@ import ( func TestGetAccountIDByPublicKey(t *testing.T) { type args struct { - accountType int32 + accountType uint32 publicKey []byte } tests := []struct { @@ -22,8 +22,8 @@ func TestGetAccountIDByPublicKey(t *testing.T) { publicKey: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, 11}, }, - want: []byte{7, 205, 139, 247, 101, 123, 250, 42, 95, 96, 199, 181, 108, 85, 197, 164, 168, 36, 49, 12, 251, 252, - 209, 82, 181, 112, 94, 41, 107, 240, 83, 180}, + want: []byte{61, 173, 177, 191, 183, 169, 194, 0, 147, 155, 147, 2, 103, 251, 133, 203, 243, 56, 197, 6, 238, 74, + 226, 190, 77, 169, 58, 218, 234, 86, 88, 130}, }, } for _, tt := range tests { @@ -74,3 +74,81 @@ func TestGetChecksumByte(t *testing.T) { }) } } + +func TestGetPrivateKeyFromSeed(t *testing.T) { + type args struct { + seed string + } + tests := []struct { + name string + args args + want []byte + wantErr bool + }{ + { + name: "GetPrivateKeyFromSeed:success", + args: args{ + seed: "first elegant bird flavor life run february tissue grant begin farm surprise", + }, + want: []byte{246, 188, 143, 79, 238, 206, 8, 182, 67, 60, 246, 31, 13, 81, 144, 22, 11, 79, 129, 224, 242, 91, 106, 213, 28, 34, + 100, 32, 202, 210, 159, 195, 182, 133, 198, 136, 42, 100, 135, 101, 197, 113, 115, 127, 171, 250, 37, 12, 39, 182, 243, 203, + 196, 207, 176, 95, 108, 116, 117, 192, 61, 215, 173, 206}, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetPrivateKeyFromSeed(tt.args.seed) + if (err != nil) != tt.wantErr { + t.Errorf("GetPrivateKeyFromSeed() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetPrivateKeyFromSeed() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetAddressFromPublicKey(t *testing.T) { + type args struct { + publicKey []byte + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "GetAddressFromPublicKey:success", + args: args{ + publicKey: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, + 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, 11}, + }, + want: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", + wantErr: false, + }, + { + name: "GetAddressFromPublicKey:fail-{public key length < 32}", + args: args{ + publicKey: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, + 84, 174, 239, 46, 190, 78, 68, 90, 83}, + }, + want: "", + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetAddressFromPublicKey(tt.args.publicKey) + if (err != nil) != tt.wantErr { + t.Errorf("GetAddressFromPublicKey() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetAddressFromPublicKey() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/core/util/transactionUtil.go b/core/util/transactionUtil.go index ae96ab3a3..f51e9e781 100644 --- a/core/util/transactionUtil.go +++ b/core/util/transactionUtil.go @@ -14,12 +14,15 @@ import ( func GetTransactionBytes(transaction *model.Transaction, sign bool) ([]byte, error) { buffer := bytes.NewBuffer([]byte{}) buffer.Write(util.ConvertUint32ToBytes(transaction.TransactionType)[:2]) + buffer.Write(util.ConvertUint32ToBytes(transaction.Version)[:1]) buffer.Write(util.ConvertUint64ToBytes(uint64(transaction.Timestamp))) - buffer.Write(transaction.SenderAccountID) - if transaction.RecipientAccountID == nil { - buffer.Write(make([]byte, 32)) + buffer.Write(util.ConvertUint32ToBytes(transaction.SenderAccountType)[:2]) + buffer.Write([]byte(transaction.SenderAccountAddress)) + buffer.Write(util.ConvertUint32ToBytes(transaction.RecipientAccountType)[:2]) + if transaction.RecipientAccountAddress == "" { + buffer.Write(make([]byte, 44)) // if no recipient pad with 44 (zoobc address length) } else { - buffer.Write(transaction.RecipientAccountID) + buffer.Write([]byte(transaction.RecipientAccountAddress)) } buffer.Write(util.ConvertUint64ToBytes(uint64(transaction.Fee))) // transaction body length @@ -37,11 +40,20 @@ func GetTransactionBytes(transaction *model.Transaction, sign bool) ([]byte, err // ParseTransactionBytes build transaction from transaction bytes func ParseTransactionBytes(transactionBytes []byte, sign bool) (*model.Transaction, error) { buffer := bytes.NewBuffer(transactionBytes) + transactionTypeBytes := buffer.Next(2) transactionType := util.ConvertBytesToUint32([]byte{transactionTypeBytes[0], transactionTypeBytes[1], 0, 0}) + transactionVersionByte := buffer.Next(1) + transactionVersion := util.ConvertBytesToUint32([]byte{transactionVersionByte[0], 0, 0, 0}) timestamp := util.ConvertBytesToUint64(buffer.Next(8)) - senderAccountID := buffer.Next(32) - recipientAccountID := buffer.Next(32) + senderAccountType := buffer.Next(2) + senderAccountAddress := ReadAccountAddress(util.ConvertBytesToUint32([]byte{ + senderAccountType[0], senderAccountType[1], 0, 0, + }), buffer) + recipientAccountType := buffer.Next(2) + recipientAccountAddress := ReadAccountAddress(util.ConvertBytesToUint32([]byte{ + recipientAccountType[0], recipientAccountType[1], 0, 0, + }), buffer) fee := util.ConvertBytesToUint64(buffer.Next(8)) transactionBodyLength := util.ConvertBytesToUint32(buffer.Next(4)) transactionBodyBytes := buffer.Next(int(transactionBodyLength)) @@ -53,13 +65,28 @@ func ParseTransactionBytes(transactionBytes []byte, sign bool) (*model.Transacti } } return &model.Transaction{ - TransactionType: transactionType, - Timestamp: int64(timestamp), - SenderAccountID: senderAccountID, - RecipientAccountID: recipientAccountID, - Fee: int64(fee), - TransactionBodyLength: transactionBodyLength, - TransactionBodyBytes: transactionBodyBytes, - Signature: signature, + TransactionType: transactionType, + Version: transactionVersion, + Timestamp: int64(timestamp), + SenderAccountType: util.ConvertBytesToUint32([]byte{ + senderAccountType[0], senderAccountType[1], 0, 0}), + SenderAccountAddress: string(senderAccountAddress), + RecipientAccountType: util.ConvertBytesToUint32([]byte{ + recipientAccountType[0], recipientAccountType[1], 0, 0, + }), + RecipientAccountAddress: string(recipientAccountAddress), + Fee: int64(fee), + TransactionBodyLength: transactionBodyLength, + TransactionBodyBytes: transactionBodyBytes, + Signature: signature, }, nil } + +func ReadAccountAddress(accountType uint32, buf *bytes.Buffer) []byte { + switch accountType { + case 0: + return buf.Next(44) // zoobc account address length + default: + return buf.Next(44) // default to zoobc account address + } +} diff --git a/core/util/transactionUtil_test.go b/core/util/transactionUtil_test.go index d17873be8..063862096 100644 --- a/core/util/transactionUtil_test.go +++ b/core/util/transactionUtil_test.go @@ -22,63 +22,68 @@ func TestGetTransactionBytes(t *testing.T) { name: "GetTransactionBytes:success", args: args{ transaction: &model.Transaction{ - TransactionType: 2, - Timestamp: 1562806389280, - SenderAccountID: []byte{4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, - 77, 80, 80, 39, 254, 173, 28, 169}, - RecipientAccountID: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, - 46, 190, 78, 68, 90, 83, 142, 11}, - Fee: 1000000, - TransactionBodyLength: 8, - TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, + TransactionType: 2, + Version: 1, + Timestamp: 1562806389280, + SenderAccountType: 0, + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountType: 0, + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionBodyLength: 8, + TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, Signature: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, 11, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, 77, 80, 80, 39, 254, 173, 28, 169}, }, sign: true, }, - want: []byte{2, 0, 32, 10, 133, 222, 107, 1, 0, 0, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, - 139, 255, 81, 229, 184, 77, 80, 80, 39, 254, 173, 28, 169, 4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, - 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, 11, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 4, - 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, - 11, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, 77, 80, 80, 39, 254, - 173, 28, 169}, + want: []byte{2, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 0, 0, 66, 67, 90, 68, 95, 86, 120, 102, 79, 50, 83, 57, 97, 122, 105, 73, 76, + 51, 99, 110, 95, 99, 88, 87, 55, 117, 80, 68, 86, 80, 79, 114, 110, 88, 117, 80, 57, 56, 71, 69, 65, 85, 67, 55, 0, 0, 66, 67, + 90, 75, 76, 118, 103, 85, 89, 90, 49, 75, 75, 120, 45, 106, 116, 70, 57, 75, 111, 74, 115, 107, 106, 86, 80, 118, 66, 57, 106, + 112, 73, 106, 102, 122, 122, 73, 54, 122, 68, 87, 48, 74, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 4, 38, + 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, + 11, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, 77, 80, 80, 39, + 254, 173, 28, 169}, wantErr: false, }, { name: "GetTransactionBytes:success-{without-signature}", args: args{ transaction: &model.Transaction{ - TransactionType: 2, - Timestamp: 1562806389280, - SenderAccountID: []byte{4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, - 77, 80, 80, 39, 254, 173, 28, 169}, - RecipientAccountID: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, - 46, 190, 78, 68, 90, 83, 142, 11}, - Fee: 1000000, - TransactionBodyLength: 8, - TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, + Version: 1, + TransactionType: 2, + Timestamp: 1562806389280, + SenderAccountType: 0, + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountType: 0, + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionBodyLength: 8, + TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }, sign: false, }, - want: []byte{2, 0, 32, 10, 133, 222, 107, 1, 0, 0, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, - 139, 255, 81, 229, 184, 77, 80, 80, 39, 254, 173, 28, 169, 4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, - 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, 11, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}, + want: []byte{2, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 0, 0, 66, 67, 90, 68, 95, 86, 120, 102, 79, 50, 83, 57, 97, 122, 105, 73, 76, + 51, 99, 110, 95, 99, 88, 87, 55, 117, 80, 68, 86, 80, 79, 114, 110, 88, 117, 80, 57, 56, 71, 69, 65, 85, 67, 55, 0, 0, 66, 67, + 90, 75, 76, 118, 103, 85, 89, 90, 49, 75, 75, 120, 45, 106, 116, 70, 57, 75, 111, 74, 115, 107, 106, 86, 80, 118, 66, 57, 106, + 112, 73, 106, 102, 122, 122, 73, 54, 122, 68, 87, 48, 74, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}, wantErr: false, }, { name: "GetTransactionBytes:fail-{sign:true, no signature}", args: args{ transaction: &model.Transaction{ - TransactionType: 2, - Timestamp: 1562806389280, - SenderAccountID: []byte{4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, - 77, 80, 80, 39, 254, 173, 28, 169}, - RecipientAccountID: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, - 46, 190, 78, 68, 90, 83, 142, 11}, - Fee: 1000000, - TransactionBodyLength: 8, - TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, + TransactionType: 2, + Version: 1, + Timestamp: 1562806389280, + SenderAccountType: 0, + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountType: 0, + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionBodyLength: 8, + TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }, sign: true, }, @@ -89,19 +94,21 @@ func TestGetTransactionBytes(t *testing.T) { name: "GetTransactionBytes:success-{without recipient}", args: args{ transaction: &model.Transaction{ - TransactionType: 2, - Timestamp: 1562806389280, - SenderAccountID: []byte{4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, - 77, 80, 80, 39, 254, 173, 28, 169}, + Version: 1, + TransactionType: 2, + Timestamp: 1562806389280, + SenderAccountType: 0, + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", Fee: 1000000, TransactionBodyLength: 8, TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }, sign: false, }, - want: []byte{2, 0, 32, 10, 133, 222, 107, 1, 0, 0, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, - 56, 139, 255, 81, 229, 184, 77, 80, 80, 39, 254, 173, 28, 169, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}, + want: []byte{2, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 0, 0, 66, 67, 90, 68, 95, 86, 120, 102, 79, 50, 83, 57, 97, 122, 105, 73, 76, + 51, 99, 110, 95, 99, 88, 87, 55, 117, 80, 68, 86, 80, 79, 114, 110, 88, 117, 80, 57, 56, 71, 69, 65, 85, 67, 55, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}, wantErr: false, }, } @@ -133,63 +140,68 @@ func TestParseTransactionBytes(t *testing.T) { { name: "ParseTransactionBytes:success", args: args{ - transactionBytes: []byte{2, 0, 32, 10, 133, 222, 107, 1, 0, 0, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, - 72, 239, 56, 139, 255, 81, 229, 184, 77, 80, 80, 39, 254, 173, 28, 169, 4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, - 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, 11, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, - 6, 7, 8, 4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, - 83, 142, 11, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, 77, 80, 80, - 39, 254, 173, 28, 169}, + transactionBytes: []byte{2, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 0, 0, 66, 67, 90, 68, 95, 86, 120, 102, 79, 50, 83, 57, 97, 122, + 105, 73, 76, 51, 99, 110, 95, 99, 88, 87, 55, 117, 80, 68, 86, 80, 79, 114, 110, 88, 117, 80, 57, 56, 71, 69, 65, 85, 67, 55, + 0, 0, 66, 67, 90, 75, 76, 118, 103, 85, 89, 90, 49, 75, 75, 120, 45, 106, 116, 70, 57, 75, 111, 74, 115, 107, 106, 86, 80, + 118, 66, 57, 106, 112, 73, 106, 102, 122, 122, 73, 54, 122, 68, 87, 48, 74, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, + 5, 6, 7, 8, 4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, + 78, 68, 90, 83, 142, 11, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, + 229, 184, 77, 80, 80, 39, 254, 173, 28, 169}, sign: true, }, want: &model.Transaction{ - TransactionType: 2, - BlockID: 0, - Height: 0, - Timestamp: 1562806389280, - SenderAccountID: []byte{4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, - 77, 80, 80, 39, 254, 173, 28, 169}, - RecipientAccountID: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, - 46, 190, 78, 68, 90, 83, 142, 11}, - Fee: 1000000, - TransactionBodyLength: 8, - TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, - Signature: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, - 68, 90, 83, 142, 11, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, - 77, 80, 80, 39, 254, 173, 28, 169}, + Version: 1, + TransactionType: 2, + BlockID: 0, + Height: 0, + Timestamp: 1562806389280, + SenderAccountType: 0, + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountType: 0, + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionBodyLength: 8, + TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, + Signature: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, + 78, 68, 90, 83, 142, 11, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, + 229, 184, 77, 80, 80, 39, 254, 173, 28, 169}, }, wantErr: false, }, { name: "ParseTransactionBytes:success-{without-signature}", args: args{ - transactionBytes: []byte{2, 0, 32, 10, 133, 222, 107, 1, 0, 0, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, - 72, 239, 56, 139, 255, 81, 229, 184, 77, 80, 80, 39, 254, 173, 28, 169, 4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, - 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, 11, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, - 6, 7, 8}, + transactionBytes: []byte{2, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 0, 0, 66, 67, 90, 68, 95, 86, 120, 102, 79, 50, 83, 57, 97, 122, + 105, 73, 76, 51, 99, 110, 95, 99, 88, 87, 55, 117, 80, 68, 86, 80, 79, 114, 110, 88, 117, 80, 57, 56, 71, 69, 65, 85, 67, 55, + 0, 0, 66, 67, 90, 75, 76, 118, 103, 85, 89, 90, 49, 75, 75, 120, 45, 106, 116, 70, 57, 75, 111, 74, 115, 107, 106, 86, 80, + 118, 66, 57, 106, 112, 73, 106, 102, 122, 122, 73, 54, 122, 68, 87, 48, 74, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, + 4, 5, 6, 7, 8}, sign: false, }, want: &model.Transaction{ - TransactionType: 2, - BlockID: 0, - Height: 0, - Timestamp: 1562806389280, - SenderAccountID: []byte{4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, 72, 239, 56, 139, 255, 81, 229, 184, - 77, 80, 80, 39, 254, 173, 28, 169}, - RecipientAccountID: []byte{4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, - 46, 190, 78, 68, 90, 83, 142, 11}, - Fee: 1000000, - TransactionBodyLength: 8, - TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, + Version: 1, + TransactionType: 2, + BlockID: 0, + Height: 0, + Timestamp: 1562806389280, + SenderAccountType: 0, + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountType: 0, + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionBodyLength: 8, + TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }, wantErr: false, }, { name: "ParseTransactionBytes:fail", args: args{ - transactionBytes: []byte{2, 0, 32, 10, 133, 222, 107, 1, 0, 0, 4, 38, 68, 24, 230, 247, 88, 220, 119, 124, 51, 149, 127, 214, 82, 224, - 72, 239, 56, 139, 255, 81, 229, 184, 77, 80, 80, 39, 254, 173, 28, 169, 4, 38, 103, 73, 250, 169, 63, 155, 106, 21, 9, 76, 77, 137, - 3, 120, 21, 69, 90, 118, 242, 84, 174, 239, 46, 190, 78, 68, 90, 83, 142, 11, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, - 6, 7, 8}, + transactionBytes: []byte{2, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 0, 0, 66, 67, 90, 68, 95, 86, 120, 102, 79, 50, 83, 57, 97, 122, + 105, 73, 76, 51, 99, 110, 95, 99, 88, 87, 55, 117, 80, 68, 86, 80, 79, 114, 110, 88, 117, 80, 57, 56, 71, 69, 65, 85, 67, 55, + 0, 0, 66, 67, 90, 75, 76, 118, 103, 85, 89, 90, 49, 75, 75, 120, 45, 106, 116, 70, 57, 75, 111, 74, 115, 107, 106, 86, 80, + 118, 66, 57, 106, 112, 73, 106, 102, 122, 122, 73, 54, 122, 68, 87, 48, 74, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, + 4, 5, 6, 7, 8}, sign: true, }, want: nil, diff --git a/readme.md b/readme.md index 27800f631..33c146943 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,14 @@ - run all tests `go test ./...` - run all test with coverage report `go test ./... -coverprofile=cover.out && go tool cover -html=cover.out` +### Lint + +- run `golangci-lint ./...` to check any linting error in the changes. +- remember to run tests, and lint before submitting PR. + ### Swagger - install `go-swagger` `https://github.com/go-swagger/go-swagger` - pull newest `schema` and run `./compile-go.sh` to recompile the go file and produce swagger definition from it. + +