From d2d44e25b91ac9faef3a2a25bb1e7a37ce4c0f55 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 12:41:01 +0800 Subject: [PATCH 01/27] #134 omit account type --- api/service/accountBalanceApiService.go | 4 +- api/service/transactionApiService.go | 15 +-- common/constant/fieldsSize.go | 8 +- common/crypto/signature.go | 29 ++--- common/database/migration.go | 23 ++-- common/query/accountBalanceQuery.go | 38 +++--- common/query/accountQuery.go | 88 ------------- common/query/accountQuery_test.go | 125 ------------------- common/query/blockQuery.go | 10 +- common/query/mempoolQuery.go | 8 +- common/query/nodeRegistrationQuery.go | 14 +-- common/query/transactionQuery.go | 6 - common/transaction/fixtureGenerator.go | 3 - common/transaction/nodeRegistration.go | 65 ++++------ common/transaction/nodeRegistrationUpdate.go | 49 +++----- common/transaction/sendMoney.go | 78 +++--------- common/transaction/transaction.go | 36 +++--- common/util/account.go | 43 ------- common/util/nodeRegistration.go | 4 +- common/util/transaction.go | 49 +++----- 20 files changed, 165 insertions(+), 530 deletions(-) delete mode 100644 common/query/accountQuery.go delete mode 100644 common/query/accountQuery_test.go diff --git a/api/service/accountBalanceApiService.go b/api/service/accountBalanceApiService.go index a7e71fee5..e9f2fd2da 100644 --- a/api/service/accountBalanceApiService.go +++ b/api/service/accountBalanceApiService.go @@ -4,7 +4,6 @@ import ( "errors" "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/common/query" - "github.com/zoobc/zoobc-core/common/util" ) type ( @@ -31,8 +30,7 @@ func (abs *AccountBalanceService) GetAccountBalance(request *model.GetAccountBal err error accountBalances []*model.AccountBalance ) - accountID := util.CreateAccountIDFromAddress(request.AccountType, request.AccountAddress) - accountBalanceQuery, arg := abs.AccountBalanceQuery.GetAccountBalanceByAccountID(accountID) + accountBalanceQuery, arg := abs.AccountBalanceQuery.GetAccountBalanceByAccountAddress(request.AccountAddress) rows, err := abs.Executor.ExecuteSelect(accountBalanceQuery, arg) if err != nil { diff --git a/api/service/transactionApiService.go b/api/service/transactionApiService.go index f6e525d1d..96ab81ecc 100644 --- a/api/service/transactionApiService.go +++ b/api/service/transactionApiService.go @@ -122,9 +122,6 @@ func (ts *TransactionService) GetTransactions(chainType contract.ChainType, func (ts *TransactionService) PostTransaction(chaintype contract.ChainType, req *model.PostTransactionRequest) (*model.Transaction, error) { - var ( - senderAccountID, recipientAccountID []byte - ) txBytes := req.TransactionBytes // get unsigned bytes tx, err := util.ParseTransactionBytes(txBytes, true) @@ -134,22 +131,14 @@ func (ts *TransactionService) PostTransaction(chaintype contract.ChainType, req // Validate Tx txType := ts.ActionTypeSwitcher.GetTransactionType(tx) - if tx.RecipientAccountAddress == "" { - recipientAccountID = nil - } else { - recipientAccountID = util.CreateAccountIDFromAddress( - tx.RecipientAccountType, tx.RecipientAccountAddress) - } - senderAccountID = util.CreateAccountIDFromAddress( - tx.SenderAccountType, tx.SenderAccountAddress) // Save to mempool mpTx := &model.MempoolTransaction{ FeePerByte: 0, ID: tx.ID, TransactionBytes: txBytes, ArrivalTimestamp: time.Now().Unix(), - SenderAccountID: senderAccountID, - RecipientAccountID: recipientAccountID, + SenderAccountAddress: tx.RecipientAccountAddress, + RecipientAccountAddress: tx.RecipientAccountAddress, } if err := ts.MempoolService.ValidateMempoolTransaction(mpTx); err != nil { return nil, err diff --git a/common/constant/fieldsSize.go b/common/constant/fieldsSize.go index 029caa2b5..51109b415 100644 --- a/common/constant/fieldsSize.go +++ b/common/constant/fieldsSize.go @@ -1,10 +1,10 @@ package constant var ( - AccountType uint32 = 4 - NodeAddressLength uint32 = 4 - AccountID uint32 = 8 - AccountAddress uint32 = 44 + AccountAddressLength uint32 = 4 + NodeAddressLength uint32 = 4 + AccountID uint32 = 8 + AccountAddress uint32 = 44 // NodePublicKey TODO: this is valid for pub keys generated using Ed25519. in future we might have more implementations NodePublicKey uint32 = 32 Balance uint32 = 8 diff --git a/common/crypto/signature.go b/common/crypto/signature.go index 7913e1c67..d6c7c78e8 100644 --- a/common/crypto/signature.go +++ b/common/crypto/signature.go @@ -7,9 +7,9 @@ import ( type ( SignatureInterface interface { - Sign(payload []byte, accountType uint32, accountAddress, seed string) []byte + Sign(payload []byte, accountAddress, seed string) []byte SignByNode(payload []byte, nodeSeed string) []byte - VerifySignature(payload, signature []byte, accountType uint32, accountAddress string) bool + VerifySignature(payload, signature []byte, accountAddress string) bool } // Signature object handle signing and verifying different signature @@ -24,17 +24,10 @@ func NewSignature() *Signature { // Sign accept account ID and payload to be signed then return the signature byte based on the // signature method associated with account.Type -func (sig *Signature) Sign(payload []byte, accountType uint32, accountAddress, seed string) []byte { - switch accountType { - case 0: // zoobc - accountPrivateKey := ed25519GetPrivateKeyFromSeed(seed) - signature := ed25519.Sign(accountPrivateKey, payload) - return signature - default: - accountPrivateKey := ed25519GetPrivateKeyFromSeed(seed) - signature := ed25519.Sign(accountPrivateKey, payload) - return signature - } +func (sig *Signature) Sign(payload []byte, accountAddress, seed string) []byte { + accountPrivateKey := ed25519GetPrivateKeyFromSeed(seed) + signature := ed25519.Sign(accountPrivateKey, payload) + return signature } // SignByNode special method for signing block only, there will be no multiple signature options @@ -45,16 +38,16 @@ func (*Signature) SignByNode(payload []byte, nodeSeed string) []byte { // VerifySignature accept payload (before without signature), signature and the account id // then verify the signature + public key against the payload based on the -func (*Signature) VerifySignature(payload, signature []byte, accountType uint32, accountAddress string) bool { - - switch accountType { +func (*Signature) VerifySignature(payload, signature []byte, accountAddress string) bool { + accountType := signature[:4] + switch util.ConvertBytesToUint32(accountType) { case 0: // zoobc accountPublicKey, _ := util.GetPublicKeyFromAddress(accountAddress) - result := ed25519.Verify(accountPublicKey, payload, signature) + result := ed25519.Verify(accountPublicKey, payload, signature[4:]) return result default: accountPublicKey, _ := util.GetPublicKeyFromAddress(accountAddress) - result := ed25519.Verify(accountPublicKey, payload, signature) + result := ed25519.Verify(accountPublicKey, payload, signature[4:]) return result } } diff --git a/common/database/migration.go b/common/database/migration.go index 963abbe41..9e8ce704d 100644 --- a/common/database/migration.go +++ b/common/database/migration.go @@ -56,9 +56,9 @@ func (m *Migration) Init() error { "id" INTEGER, "block_id" INTEGER, "block_height" INTEGER, - "sender_account_type" INTEGER, + "sender_account_address_length" INTEGER, "sender_account_address" TEXT, - "recipient_account_type" INTEGER, + "recipient_account_address_length" INTEGER, "recipient_account_address" TEXT, "transaction_type" INTEGER, "fee" INTEGER, @@ -71,22 +71,14 @@ func (m *Migration) Init() error { PRIMARY KEY("id") );`, ` - CREATE TABLE IF NOT EXISTS "account" ( - "id" BLOB, - "account_type" INTEGER, - "address" TEXT, - PRIMARY KEY("id") - );`, - ` CREATE TABLE IF NOT EXISTS "account_balance" ( - "account_id" BLOB, + "account_address" VARCHAR(255), "block_height" INTEGER, "spendable_balance" INTEGER, "balance" INTEGER, "pop_revenue" INTEGER, "latest" INTEGER, - PRIMARY KEY("account_id","block_height"), - FOREIGN KEY("account_id") REFERENCES account(id) + PRIMARY KEY("account_address","block_height") );`, ` CREATE TABLE IF NOT EXISTS "main_block" ( @@ -98,7 +90,8 @@ func (m *Migration) Init() error { "block_signature" BLOB, "cumulative_difficulty" TEXT, "smith_scale" INTEGER, - "blocksmith_id" BLOB, + "blocksmith_address_length" INTEGER, + "blocksmith_address" VARCHAR(255), "total_amount" INTEGER, "total_fee" INTEGER, "total_coinbase" INTEGER, @@ -111,7 +104,7 @@ func (m *Migration) Init() error { CREATE TABLE IF NOT EXISTS "node_registry" ( "id" INTEGER, "node_public_key" BLOB, - "account_id" BLOB, + "account_address" VARCHAR(255), "registration_height" INTEGER, "node_address" VARCHAR(255), "locked_balance" INTEGER, @@ -119,7 +112,7 @@ func (m *Migration) Init() error { "latest" INTEGER, "height" INTEGER, UNIQUE ("node_public_key", "height"), - UNIQUE ("account_id", "height"), + UNIQUE ("account_address", "height"), PRIMARY KEY("id", "height") );`, } diff --git a/common/query/accountBalanceQuery.go b/common/query/accountBalanceQuery.go index adbb7f25a..c2086a0fa 100644 --- a/common/query/accountBalanceQuery.go +++ b/common/query/accountBalanceQuery.go @@ -16,7 +16,7 @@ type ( } // AccountBalanceQueryInterface interface that implemented by AccountBalanceQuery AccountBalanceQueryInterface interface { - GetAccountBalanceByAccountID(accountID []byte) (string, interface{}) + GetAccountBalanceByAccountAddress(accountAddress string) (string, interface{}) InsertAccountBalance(accountBalance *model.AccountBalance) (str string, args []interface{}) AddAccountBalance(balance int64, causedFields map[string]interface{}) [][]interface{} AddAccountSpendableBalance(balance int64, causedFields map[string]interface{}) (str string, args []interface{}) @@ -29,7 +29,7 @@ type ( func NewAccountBalanceQuery() *AccountBalanceQuery { return &AccountBalanceQuery{ Fields: []string{ - "account_id", + "account_address", "block_height", "spendable_balance", "balance", @@ -39,9 +39,9 @@ func NewAccountBalanceQuery() *AccountBalanceQuery { TableName: "account_balance", } } -func (q *AccountBalanceQuery) GetAccountBalanceByAccountID(accountID []byte) (query string, args interface{}) { - return fmt.Sprintf(`SELECT %s FROM %s WHERE account_id = ? AND latest = 1`, - strings.Join(q.Fields, ","), q.TableName), accountID +func (q *AccountBalanceQuery) GetAccountBalanceByAccountAddress(accountAddress string) (query string, args interface{}) { + return fmt.Sprintf(`SELECT %s FROM %s WHERE account_address = ? AND latest = 1`, + strings.Join(q.Fields, ","), q.TableName), accountAddress } func (q *AccountBalanceQuery) AddAccountBalance(balance int64, causedFields map[string]interface{}) [][]interface{} { @@ -50,31 +50,31 @@ func (q *AccountBalanceQuery) AddAccountBalance(balance int64, causedFields map[ updateVersionQuery string ) // insert account if account not in account balance yet - insertBalanceQuery := fmt.Sprintf("INSERT INTO %s (account_id, block_height, spendable_balance, balance, pop_revenue, latest) "+ - "SELECT ?, %d, 0, 0, 0, 1 WHERE NOT EXISTS (SELECT account_id FROM %s WHERE account_id = ?)", q.TableName, + insertBalanceQuery := fmt.Sprintf("INSERT INTO %s (account_address, block_height, spendable_balance, balance, pop_revenue, latest) "+ + "SELECT ?, %d, 0, 0, 0, 1 WHERE NOT EXISTS (SELECT account_address FROM %s WHERE account_address = ?)", q.TableName, causedFields["block_height"], q.TableName) // update or insert new account_balance row - updateBalanceQuery := fmt.Sprintf("INSERT INTO %s (account_id, block_height, spendable_balance, balance, pop_revenue, latest) "+ - "SELECT account_id, %d, spendable_balance + %d, balance + %d, pop_revenue, latest FROM account_balance WHERE account_id = ? AND "+ - "latest = 1 ON CONFLICT(account_id, block_height) DO UPDATE SET (spendable_balance, balance) = (SELECT "+ - "spendable_balance + %d, balance + %d FROM %s WHERE account_id = ? AND latest = 1)", + updateBalanceQuery := fmt.Sprintf("INSERT INTO %s (account_address, block_height, spendable_balance, balance, pop_revenue, latest) "+ + "SELECT account_address, %d, spendable_balance + %d, balance + %d, pop_revenue, latest FROM account_balance WHERE account_address = ? AND "+ + "latest = 1 ON CONFLICT(account_address, block_height) DO UPDATE SET (spendable_balance, balance) = (SELECT "+ + "spendable_balance + %d, balance + %d FROM %s WHERE account_address = ? AND latest = 1)", q.TableName, causedFields["block_height"], balance, balance, balance, balance, q.TableName) queries = append(queries, []interface{}{ - insertBalanceQuery, causedFields["account_id"], causedFields["account_id"], + insertBalanceQuery, causedFields["account_address"], causedFields["account_address"], }, []interface{}{ - updateBalanceQuery, causedFields["account_id"], causedFields["account_id"], + updateBalanceQuery, causedFields["account_address"], causedFields["account_address"], }, ) if causedFields["block_height"].(uint32) != 0 { // set previous version record to latest = false - updateVersionQuery = fmt.Sprintf("UPDATE %s SET latest = false WHERE account_id = ? AND block_height != %d AND latest = true", + updateVersionQuery = fmt.Sprintf("UPDATE %s SET latest = false WHERE account_address = ? AND block_height != %d AND latest = true", q.TableName, causedFields["block_height"]) queries = append(queries, []interface{}{ - updateVersionQuery, causedFields["account_id"], + updateVersionQuery, causedFields["account_address"], }, ) } @@ -83,8 +83,8 @@ func (q *AccountBalanceQuery) AddAccountBalance(balance int64, causedFields map[ func (q *AccountBalanceQuery) AddAccountSpendableBalance(balance int64, causedFields map[string]interface{}) ( str string, args []interface{}) { - return fmt.Sprintf("UPDATE %s SET spendable_balance = spendable_balance + (%d) WHERE account_id = ?", - q.TableName, balance), []interface{}{causedFields["account_id"]} + return fmt.Sprintf("UPDATE %s SET spendable_balance = spendable_balance + (%d) WHERE account_address = ?", + q.TableName, balance), []interface{}{causedFields["account_address"]} } func (q *AccountBalanceQuery) InsertAccountBalance(accountBalance *model.AccountBalance) (str string, args []interface{}) { @@ -98,7 +98,7 @@ func (q *AccountBalanceQuery) InsertAccountBalance(accountBalance *model.Account func (*AccountBalanceQuery) ExtractModel(account *model.AccountBalance) []interface{} { return []interface{}{ - account.AccountID, + account.AccountAddress, account.BlockHeight, account.SpendableBalance, account.Balance, @@ -113,7 +113,7 @@ func (*AccountBalanceQuery) BuildModel(accountBalances []*model.AccountBalance, for rows.Next() { var accountBalance model.AccountBalance _ = rows.Scan( - &accountBalance.AccountID, + &accountBalance.AccountAddress, &accountBalance.BlockHeight, &accountBalance.SpendableBalance, &accountBalance.Balance, diff --git a/common/query/accountQuery.go b/common/query/accountQuery.go deleted file mode 100644 index 3d965e488..000000000 --- a/common/query/accountQuery.go +++ /dev/null @@ -1,88 +0,0 @@ -package query - -import ( - "database/sql" - "fmt" - "strings" - - "github.com/zoobc/zoobc-core/common/model" -) - -type ( - AccountQuery struct { - Fields []string - TableName string - } - - AccountQueryInterface interface { - GetAccountByID(accountID []byte) (str string, args []interface{}) - GetAccountByIDs(ids [][]byte) (str string, args []interface{}) - InsertAccount(account *model.Account) (str string, args []interface{}) - ExtractModel(account *model.Account) []interface{} - BuildModel(accounts []*model.Account, rows *sql.Rows) []*model.Account - GetTableName() string - } -) - -// NewAccountQuery returns AccountQuery instance -func NewAccountQuery() *AccountQuery { - return &AccountQuery{ - Fields: []string{"id", "account_type", "address"}, - TableName: "account", - } -} - -// GetAccountByID returns query string to get account by ID -func (aq *AccountQuery) GetAccountByID(accountID []byte) (str string, args []interface{}) { - return fmt.Sprintf("SELECT %s FROM %s WHERE id = ?", strings.Join(aq.Fields, ", "), aq.TableName), - []interface{}{accountID} -} - -// GetAccountByIDs return query string to get accounts by multiple IDs -func (aq *AccountQuery) GetAccountByIDs(ids [][]byte) (str string, args []interface{}) { - for _, id := range ids { - args = append(args, id) - } - return fmt.Sprintf( - "SELECT %s FROM %s WHERE id in (%s)", - strings.Join(aq.Fields, ","), - aq.TableName, - fmt.Sprintf("? %s", strings.Repeat(",?", len(ids)-1)), - ), args -} - -func (aq *AccountQuery) InsertAccount(account *model.Account) (str string, args []interface{}) { - return fmt.Sprintf( - "INSERT OR IGNORE INTO %s (%s) VALUES(%s)", - aq.TableName, - strings.Join(aq.Fields, ","), - fmt.Sprintf("? %s", strings.Repeat(", ?", len(aq.Fields)-1)), - ), aq.ExtractModel(account) -} - -func (aq *AccountQuery) ExtractModel(account *model.Account) []interface{} { - return []interface{}{ - account.ID, - account.AccountType, - account.Address, - } -} - -// BuildModel will only be used for mapping the result of `select` query, which will guarantee that -// the result of build model will be correctly mapped based on the modelQuery.Fields order. -func (*AccountQuery) BuildModel(accounts []*model.Account, rows *sql.Rows) []*model.Account { - for rows.Next() { - var account model.Account - _ = rows.Scan( - &account.ID, - &account.AccountType, - &account.Address) - accounts = append(accounts, &account) - } - return accounts -} - -// GetTableName is func to get account table name -func (aq *AccountQuery) GetTableName() string { - return aq.TableName -} diff --git a/common/query/accountQuery_test.go b/common/query/accountQuery_test.go deleted file mode 100644 index ae12f4952..000000000 --- a/common/query/accountQuery_test.go +++ /dev/null @@ -1,125 +0,0 @@ -package query - -import ( - "reflect" - "testing" - - "github.com/DATA-DOG/go-sqlmock" - - "github.com/zoobc/zoobc-core/common/model" -) - -func TestNewAccountQuery(t *testing.T) { - tests := []struct { - name string - want *AccountQuery - }{ - { - name: "NewAccountQuery:success", - want: NewAccountQuery(), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := NewAccountQuery(); !reflect.DeepEqual(got, tt.want) { - t.Errorf("NewAccountQuery() = %v, want %v", got, tt.want) - } - }) - } -} - -var mockAccountQuery = &AccountQuery{ - Fields: []string{"id", "account_type", "address"}, - TableName: "account", -} - -var mockAccount = &model.Account{ - ID: []byte{1}, - AccountType: 0, - Address: "bar", -} - -func TestAccountQuery_GetAccountByID(t *testing.T) { - t.Run("GetAccountByID:success", func(t *testing.T) { - q, args := mockAccountQuery.GetAccountByID(mockAccount.ID) - wantQ := "SELECT id, account_type, address FROM account WHERE id = ?" - wantArg := []interface{}{ - mockAccount.ID, - } - if q != wantQ { - t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) - } - if !reflect.DeepEqual(args, wantArg) { - t.Errorf("arguments returned wrong: get: %v\nwant: %v", args, wantArg) - } - }) -} - -func TestAccountQuery_GetAccountByIDs(t *testing.T) { - t.Run("GetAccountByIDs:success", func(t *testing.T) { - argIn := [][]byte{mockAccount.ID, {2}} - q, args := mockAccountQuery.GetAccountByIDs(argIn) - wantQ := "SELECT id,account_type,address FROM account WHERE id in (? ,?)" - wantArg := []interface{}{ - mockAccount.ID, []byte{2}, - } - if q != wantQ { - t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) - } - if !reflect.DeepEqual(args, wantArg) { - t.Errorf("arguments returned wrong: get: %v\nwant: %v", args, wantArg) - } - }) -} - -func TestAccountQuery_InsertAccount(t *testing.T) { - t.Run("InsertAccount:success", func(t *testing.T) { - q, args := mockAccountQuery.InsertAccount(mockAccount) - wantQ := "INSERT OR IGNORE INTO account (id,account_type,address) VALUES(? , ?, ?)" - wantArg := mockAccountQuery.ExtractModel(mockAccount) - - if q != wantQ { - t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) - } - if !reflect.DeepEqual(args, wantArg) { - t.Errorf("arguments returned wrong: get: %v\nwant: %v", args, wantArg) - } - }) -} - -func TestAccountQuery_ExtractModel(t *testing.T) { - t.Run("AccountQuery-ExtractModel:success", func(t *testing.T) { - res := mockAccountQuery.ExtractModel(mockAccount) - want := []interface{}{ - mockAccount.ID, mockAccount.AccountType, mockAccount.Address, - } - if !reflect.DeepEqual(res, want) { - t.Errorf("arguments returned wrong: get: %v\nwant: %v", res, want) - } - }) -} - -func TestAccountQuery_BuildModel(t *testing.T) { - t.Run("AccountQuery-BuildModel:success", func(t *testing.T) { - db, mock, _ := sqlmock.New() - defer db.Close() - mock.ExpectQuery("foo").WillReturnRows(sqlmock.NewRows([]string{ - "ID", "AccountType", "Address"}). - AddRow(mockAccount.ID, mockAccount.AccountType, mockAccount.Address)) - rows, _ := db.Query("foo") - var tempAccount []*model.Account - res := mockAccountQuery.BuildModel(tempAccount, rows) - if !reflect.DeepEqual(res[0], mockAccount) { - t.Errorf("arguments returned wrong: get: %v\nwant: %v", res, mockAccount) - } - }) -} - -func TestAccountQuery_GetTableName(t *testing.T) { - t.Run("AccountQuery-GetTableName:success", func(t *testing.T) { - res := mockAccountQuery.GetTableName() - if res != mockAccountQuery.TableName { - t.Errorf("arguments returned wrong: get: %v\nwant: %v", res, mockAccountQuery.TableName) - } - }) -} diff --git a/common/query/blockQuery.go b/common/query/blockQuery.go index cba0399cb..69ad08ec2 100644 --- a/common/query/blockQuery.go +++ b/common/query/blockQuery.go @@ -33,7 +33,8 @@ type ( func NewBlockQuery(chaintype contract.ChainType) *BlockQuery { return &BlockQuery{ Fields: []string{"id", "previous_block_hash", "height", "timestamp", "block_seed", "block_signature", "cumulative_difficulty", - "smith_scale", "payload_length", "payload_hash", "blocksmith_id", "total_amount", "total_fee", "total_coinbase", "version", + "smith_scale", "payload_length", "payload_hash", "blocksmith_address_length", "blocksmith_address", "total_amount", "total_fee", + "total_coinbase", "version", }, TableName: "block", ChainType: chaintype, @@ -87,7 +88,8 @@ func (*BlockQuery) ExtractModel(block *model.Block) []interface{} { block.SmithScale, block.PayloadLength, block.PayloadHash, - block.BlocksmithID, + block.BlocksmithAddressLength, + block.BlocksmithAddress, block.TotalAmount, block.TotalFee, block.TotalCoinBase, @@ -100,8 +102,8 @@ func (*BlockQuery) BuildModel(blocks []*model.Block, rows *sql.Rows) []*model.Bl var block model.Block _ = rows.Scan(&block.ID, &block.PreviousBlockHash, &block.Height, &block.Timestamp, &block.BlockSeed, &block.BlockSignature, &block.CumulativeDifficulty, &block.SmithScale, &block.PayloadLength, - &block.PayloadHash, &block.BlocksmithID, &block.TotalAmount, &block.TotalFee, &block.TotalCoinBase, - &block.Version) + &block.PayloadHash, &block.BlocksmithAddressLength, &block.BlocksmithAddress, &block.TotalAmount, &block.TotalFee, + &block.TotalCoinBase, &block.Version) blocks = append(blocks, &block) } return blocks diff --git a/common/query/mempoolQuery.go b/common/query/mempoolQuery.go index 83a416d74..7c83463b2 100644 --- a/common/query/mempoolQuery.go +++ b/common/query/mempoolQuery.go @@ -82,8 +82,8 @@ func (*MempoolQuery) ExtractModel(mempool *model.MempoolTransaction) []interface mempool.FeePerByte, mempool.ArrivalTimestamp, mempool.TransactionBytes, - mempool.SenderAccountID, - mempool.RecipientAccountID, + mempool.SenderAccountAddress, + mempool.RecipientAccountAddress, } } @@ -97,8 +97,8 @@ func (*MempoolQuery) BuildModel(mempools []*model.MempoolTransaction, rows *sql. &mempool.FeePerByte, &mempool.ArrivalTimestamp, &mempool.TransactionBytes, - &mempool.SenderAccountID, - &mempool.RecipientAccountID, + &mempool.SenderAccountAddress, + &mempool.RecipientAccountAddress, ) mempools = append(mempools, &mempool) } diff --git a/common/query/nodeRegistrationQuery.go b/common/query/nodeRegistrationQuery.go index 320e1a2fb..d1427a425 100644 --- a/common/query/nodeRegistrationQuery.go +++ b/common/query/nodeRegistrationQuery.go @@ -15,7 +15,7 @@ type ( GetNodeRegistrations(registrationHeight, size uint32) (str string) GetNodeRegistrationByID(id int64) (str string, args []interface{}) GetNodeRegistrationByNodePublicKey(nodePublicKey []byte) (str string, args []interface{}) - GetNodeRegistrationByAccountID(accountPublicKey []byte) (str string, args []interface{}) + GetNodeRegistrationByAccountAddress(accountAddress string) (str string, args []interface{}) ExtractModel(nr *model.NodeRegistration) []interface{} BuildModel(nodeRegistrations []*model.NodeRegistration, rows *sql.Rows) []*model.NodeRegistration } @@ -28,7 +28,7 @@ type ( func NewNodeRegistrationQuery() *NodeRegistrationQuery { return &NodeRegistrationQuery{ - Fields: []string{"id", "node_public_key", "account_id", "registration_height", "node_address", "locked_balance", "queued", + Fields: []string{"id", "node_public_key", "account_address", "registration_height", "node_address", "locked_balance", "queued", "latest", "height"}, TableName: "node_registry", } @@ -80,9 +80,9 @@ func (nr *NodeRegistrationQuery) GetNodeRegistrationByNodePublicKey(nodePublicKe } // GetNodeRegistrationByAccountID returns query string to get Node Registration by account public key -func (nr *NodeRegistrationQuery) GetNodeRegistrationByAccountID(accountPublicKey []byte) (str string, args []interface{}) { - return fmt.Sprintf("SELECT %s FROM %s WHERE account_id = %d AND latest=1", - strings.Join(nr.Fields, ", "), nr.getTableName(), accountPublicKey), []interface{}{accountPublicKey} +func (nr *NodeRegistrationQuery) GetNodeRegistrationByAccountAddress(accountAddress string) (str string, args []interface{}) { + return fmt.Sprintf("SELECT %s FROM %s WHERE account_address = %d AND latest=1", + strings.Join(nr.Fields, ", "), nr.getTableName(), accountAddress), []interface{}{accountAddress} } // ExtractModel extract the model struct fields to the order of NodeRegistrationQuery.Fields @@ -90,7 +90,7 @@ func (*NodeRegistrationQuery) ExtractModel(nr *model.NodeRegistration) []interfa return []interface{}{ nr.NodeID, nr.NodePublicKey, - nr.AccountId, + nr.AccountAddress, nr.RegistrationHeight, nr.NodeAddress, nr.LockedBalance, @@ -108,7 +108,7 @@ func (*NodeRegistrationQuery) BuildModel(nodeRegistrations []*model.NodeRegistra _ = rows.Scan( &nr.NodeID, &nr.NodePublicKey, - &nr.AccountId, + &nr.AccountAddress, &nr.RegistrationHeight, &nr.NodeAddress, &nr.LockedBalance, diff --git a/common/query/transactionQuery.go b/common/query/transactionQuery.go index 66c94784d..7325f10a2 100644 --- a/common/query/transactionQuery.go +++ b/common/query/transactionQuery.go @@ -30,9 +30,7 @@ func NewTransactionQuery(chaintype contract.ChainType) *TransactionQuery { "id", "block_id", "block_height", - "sender_account_type", "sender_account_address", - "recipient_account_type", "recipient_account_address", "transaction_type", "fee", @@ -96,9 +94,7 @@ func (*TransactionQuery) ExtractModel(tx *model.Transaction) []interface{} { &tx.ID, &tx.BlockID, &tx.Height, - &tx.SenderAccountType, &tx.SenderAccountAddress, - &tx.RecipientAccountType, &tx.RecipientAccountAddress, &tx.TransactionType, &tx.Fee, @@ -118,9 +114,7 @@ func (*TransactionQuery) BuildModel(txs []*model.Transaction, rows *sql.Rows) [] &tx.ID, &tx.BlockID, &tx.Height, - &tx.SenderAccountType, &tx.SenderAccountAddress, - &tx.RecipientAccountType, &tx.RecipientAccountAddress, &tx.TransactionType, &tx.Fee, diff --git a/common/transaction/fixtureGenerator.go b/common/transaction/fixtureGenerator.go index e4e3c181b..a49124edd 100644 --- a/common/transaction/fixtureGenerator.go +++ b/common/transaction/fixtureGenerator.go @@ -9,7 +9,6 @@ import ( func GetFixtures() (poownMessage *model.ProofOfOwnershipMessage, poown *model.ProofOfOwnership, txBody *model.NodeRegistrationTransactionBody, txBodyBytes []byte) { - senderAccountType := uint32(0) senderAddress := "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN" senderSeed := "prune filth cleaver removable earthworm tricky sulfur citation hesitate stout snort guy" poownMessage = &model.ProofOfOwnershipMessage{ @@ -23,7 +22,6 @@ func GetFixtures() (poownMessage *model.ProofOfOwnershipMessage, poown *model.Pr poownMessageBytes := util.GetProofOfOwnershipMessageBytes(poownMessage) poownSignature := crypto.NewSignature().Sign( poownMessageBytes, - senderAccountType, senderAddress, senderSeed, ) @@ -34,7 +32,6 @@ func GetFixtures() (poownMessage *model.ProofOfOwnershipMessage, poown *model.Pr txBody = &model.NodeRegistrationTransactionBody{ NodePublicKey: []byte{0, 14, 6, 218, 170, 54, 60, 50, 2, 66, 130, 119, 226, 235, 126, 203, 5, 12, 152, 194, 170, 146, 43, 63, 224, 101, 127, 241, 62, 152, 187, 255}, - AccountType: 0, AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", RegistrationHeight: 0, NodeAddressLength: 9, diff --git a/common/transaction/nodeRegistration.go b/common/transaction/nodeRegistration.go index c37f783d7..525f6699e 100644 --- a/common/transaction/nodeRegistration.go +++ b/common/transaction/nodeRegistration.go @@ -13,15 +13,14 @@ import ( // NodeRegistration Implement service layer for (new) node registration's transaction type NodeRegistration struct { - Body *model.NodeRegistrationTransactionBody - Fee int64 - SenderAddress string - SenderAccountType uint32 - Height uint32 - AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface - NodeRegistrationQuery query.NodeRegistrationQueryInterface - QueryExecutor query.ExecutorInterface + Body *model.NodeRegistrationTransactionBody + Fee int64 + SenderAddress string + SenderAccountAddressLength uint32 + Height uint32 + AccountBalanceQuery query.AccountBalanceQueryInterface + NodeRegistrationQuery query.NodeRegistrationQueryInterface + QueryExecutor query.ExecutorInterface } func (tx *NodeRegistration) ApplyConfirmed() error { @@ -46,17 +45,14 @@ func (tx *NodeRegistration) ApplyConfirmed() error { NodePublicKey: tx.Body.NodePublicKey, Latest: true, Queued: true, - AccountId: util.CreateAccountIDFromAddress(tx.Body.AccountType, tx.Body.AccountAddress), + AccountAddress: tx.Body.AccountAddress, } // update sender balance by reducing his spendable balance of the tx fee accountBalanceSenderQ := tx.AccountBalanceQuery.AddAccountBalance( -(tx.Body.LockedBalance + tx.Fee), map[string]interface{}{ - "account_id": util.CreateAccountIDFromAddress( - tx.SenderAccountType, - tx.SenderAddress, - ), - "block_height": tx.Height, + "account_address": tx.SenderAddress, + "block_height": tx.Height, }, ) insertNodeQ, insertNodeArg := tx.NodeRegistrationQuery.InsertNodeRegistration(nodeRegistration) @@ -90,10 +86,7 @@ func (tx *NodeRegistration) ApplyUnconfirmed() error { accountBalanceSenderQ, accountBalanceSenderQArgs := tx.AccountBalanceQuery.AddAccountSpendableBalance( -(tx.Body.LockedBalance + tx.Fee), map[string]interface{}{ - "account_id": util.CreateAccountIDFromAddress( - tx.SenderAccountType, - tx.SenderAddress, - ), + "account_id": tx.SenderAddress, }, ) // add row to node_registry table @@ -110,10 +103,7 @@ func (tx *NodeRegistration) UndoApplyUnconfirmed() error { accountBalanceSenderQ, accountBalanceSenderQArgs := tx.AccountBalanceQuery.AddAccountSpendableBalance( tx.Body.LockedBalance+tx.Fee, map[string]interface{}{ - "account_id": util.CreateAccountIDFromAddress( - tx.SenderAccountType, - tx.SenderAddress, - ), + "account_address": tx.SenderAddress, }, ) err := tx.QueryExecutor.ExecuteTransaction(accountBalanceSenderQ, accountBalanceSenderQArgs...) @@ -129,14 +119,13 @@ func (tx *NodeRegistration) Validate() error { accountBalance model.AccountBalance ) // check balance - senderID := util.CreateAccountIDFromAddress(tx.SenderAccountType, tx.SenderAddress) - senderQ, senderArg := tx.AccountBalanceQuery.GetAccountBalanceByAccountID(senderID) + senderQ, senderArg := tx.AccountBalanceQuery.GetAccountBalanceByAccountAddress(tx.SenderAddress) rows, err := tx.QueryExecutor.ExecuteSelect(senderQ, senderArg) if err != nil { return err } else if rows.Next() { _ = rows.Scan( - &accountBalance.AccountID, + &accountBalance.AccountAddress, &accountBalance.BlockHeight, &accountBalance.SpendableBalance, &accountBalance.Balance, @@ -170,7 +159,7 @@ func (tx *NodeRegistration) GetSize() uint32 { nodeAddress := tx.Body.NodeAddressLength // ProofOfOwnership (message + signature) poown := util.GetProofOfOwnershipSize(true) - return constant.NodePublicKey + constant.AccountType + constant.NodeAddressLength + constant.AccountAddress + + return constant.NodePublicKey + constant.AccountAddressLength + constant.NodeAddressLength + constant.AccountAddress + constant.Balance + nodeAddress + poown } @@ -178,22 +167,22 @@ func (tx *NodeRegistration) GetSize() uint32 { func (*NodeRegistration) ParseBodyBytes(txBodyBytes []byte) model.TransactionBodyInterface { buffer := bytes.NewBuffer(txBodyBytes) nodePublicKey := buffer.Next(int(constant.NodePublicKey)) - accountType := util.ConvertBytesToUint32(buffer.Next(int(constant.AccountType))) - accountAddress := buffer.Next(int(constant.AccountAddress)) + accountAddressLength := util.ConvertBytesToUint32(buffer.Next(int(constant.AccountAddressLength))) + accountAddress := buffer.Next(int(accountAddressLength)) nodeRegistrationHeight := util.ConvertBytesToUint32(buffer.Next(int(constant.Height))) nodeAddressLength := util.ConvertBytesToUint32(buffer.Next(int(constant.NodeAddressLength))) // uint32 length of next bytes to read nodeAddress := buffer.Next(int(nodeAddressLength)) // based on nodeAddressLength lockedBalance := util.ConvertBytesToUint64(buffer.Next(int(constant.Balance))) poown := util.ParseProofOfOwnershipBytes(buffer.Next(int(util.GetProofOfOwnershipSize(true)))) txBody := &model.NodeRegistrationTransactionBody{ - NodePublicKey: nodePublicKey, - AccountType: accountType, - AccountAddress: string(accountAddress), - RegistrationHeight: nodeRegistrationHeight, - NodeAddressLength: nodeAddressLength, - NodeAddress: string(nodeAddress), - LockedBalance: int64(lockedBalance), - Poown: poown, + NodePublicKey: nodePublicKey, + AccountAddressLength: accountAddressLength, + AccountAddress: string(accountAddress), + RegistrationHeight: nodeRegistrationHeight, + NodeAddressLength: nodeAddressLength, + NodeAddress: string(nodeAddress), + LockedBalance: int64(lockedBalance), + Poown: poown, } return txBody } @@ -202,7 +191,7 @@ func (*NodeRegistration) ParseBodyBytes(txBodyBytes []byte) model.TransactionBod func (tx *NodeRegistration) GetBodyBytes() []byte { buffer := bytes.NewBuffer([]byte{}) buffer.Write(tx.Body.NodePublicKey) - buffer.Write(util.ConvertUint32ToBytes(tx.Body.AccountType)) + buffer.Write(util.ConvertUint32ToBytes(tx.Body.AccountAddressLength)) buffer.Write([]byte(tx.Body.AccountAddress)) buffer.Write(util.ConvertUint32ToBytes(tx.Body.RegistrationHeight)) buffer.Write(util.ConvertUint32ToBytes(tx.Body.NodeAddressLength)) diff --git a/common/transaction/nodeRegistrationUpdate.go b/common/transaction/nodeRegistrationUpdate.go index 9cc196f38..4a119306f 100644 --- a/common/transaction/nodeRegistrationUpdate.go +++ b/common/transaction/nodeRegistrationUpdate.go @@ -14,15 +14,14 @@ import ( // UpdateNodeRegistration Implement service layer for (new) node registration's transaction type UpdateNodeRegistration struct { - Body *model.UpdateNodeRegistrationTransactionBody - Fee int64 - SenderAddress string - SenderAccountType uint32 - Height uint32 - AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface - NodeRegistrationQuery query.NodeRegistrationQueryInterface - QueryExecutor query.ExecutorInterface + Body *model.UpdateNodeRegistrationTransactionBody + Fee int64 + SenderAddress string + SenderAccountAddressLength uint32 + Height uint32 + AccountBalanceQuery query.AccountBalanceQueryInterface + NodeRegistrationQuery query.NodeRegistrationQueryInterface + QueryExecutor query.ExecutorInterface } func (tx *UpdateNodeRegistration) ApplyConfirmed() error { @@ -41,8 +40,7 @@ func (tx *UpdateNodeRegistration) ApplyConfirmed() error { } } // get the latest noderegistration by owner (sender account) - senderID := util.CreateAccountIDFromAddress(tx.SenderAccountType, tx.SenderAddress) - rows, err := tx.QueryExecutor.ExecuteSelect(tx.NodeRegistrationQuery.GetNodeRegistrationByAccountID(senderID)) + rows, err := tx.QueryExecutor.ExecuteSelect(tx.NodeRegistrationQuery.GetNodeRegistrationByAccountAddress(tx.SenderAddress)) if err != nil { // no nodes registered with this accountID return err @@ -82,7 +80,7 @@ func (tx *UpdateNodeRegistration) ApplyConfirmed() error { NodePublicKey: nodePublicKey, Latest: true, Queued: prevNodeRegistration.Queued, - AccountId: senderID, + AccountAddress: tx.SenderAddress, } var effectiveBalanceToLock int64 @@ -95,10 +93,7 @@ func (tx *UpdateNodeRegistration) ApplyConfirmed() error { accountBalanceSenderQ := tx.AccountBalanceQuery.AddAccountBalance( -(effectiveBalanceToLock + tx.Fee), map[string]interface{}{ - "account_id": util.CreateAccountIDFromAddress( - tx.SenderAccountType, - tx.SenderAddress, - ), + "account_address": tx.SenderAddress, "block_height": tx.Height, }, ) @@ -134,8 +129,7 @@ func (tx *UpdateNodeRegistration) ApplyUnconfirmed() error { var effectiveBalanceToLock int64 if tx.Body.LockedBalance > 0 { // get the latest noderegistration by owner (sender account) - senderID := util.CreateAccountIDFromAddress(tx.SenderAccountType, tx.SenderAddress) - rows, err := tx.QueryExecutor.ExecuteSelect(tx.NodeRegistrationQuery.GetNodeRegistrationByAccountID(senderID)) + rows, err := tx.QueryExecutor.ExecuteSelect(tx.NodeRegistrationQuery.GetNodeRegistrationByAccountAddress(tx.SenderAddress)) if err != nil { return err } else if rows.Next() { @@ -153,10 +147,7 @@ func (tx *UpdateNodeRegistration) ApplyUnconfirmed() error { accountBalanceSenderQ, accountBalanceSenderQArgs := tx.AccountBalanceQuery.AddAccountSpendableBalance( -(effectiveBalanceToLock + tx.Fee), map[string]interface{}{ - "account_id": util.CreateAccountIDFromAddress( - tx.SenderAccountType, - tx.SenderAddress, - ), + "account_address": tx.SenderAddress, }, ) // add row to node_registry table @@ -173,10 +164,7 @@ func (tx *UpdateNodeRegistration) UndoApplyUnconfirmed() error { accountBalanceSenderQ, accountBalanceSenderQArgs := tx.AccountBalanceQuery.AddAccountSpendableBalance( tx.Body.LockedBalance+tx.Fee, map[string]interface{}{ - "account_id": util.CreateAccountIDFromAddress( - tx.SenderAccountType, - tx.SenderAddress, - ), + "account_address": tx.SenderAddress, }, ) err := tx.QueryExecutor.ExecuteTransaction(accountBalanceSenderQ, accountBalanceSenderQArgs...) @@ -201,8 +189,7 @@ func (tx *UpdateNodeRegistration) Validate() error { // // check that sender is node's owner - senderID := util.CreateAccountIDFromAddress(tx.SenderAccountType, tx.SenderAddress) - rows, err := tx.QueryExecutor.ExecuteSelect(tx.NodeRegistrationQuery.GetNodeRegistrationByAccountID(senderID)) + rows, err := tx.QueryExecutor.ExecuteSelect(tx.NodeRegistrationQuery.GetNodeRegistrationByAccountAddress(tx.SenderAddress)) if err != nil { return err } @@ -214,7 +201,7 @@ func (tx *UpdateNodeRegistration) Validate() error { _ = rows.Scan( &prevNodeRegistration.NodeID, &prevNodeRegistration.NodePublicKey, - &prevNodeRegistration.AccountId, + &prevNodeRegistration.AccountAddress, &prevNodeRegistration.RegistrationHeight, &prevNodeRegistration.NodeAddress, &prevNodeRegistration.LockedBalance, @@ -236,13 +223,13 @@ func (tx *UpdateNodeRegistration) Validate() error { } } - rows, err = tx.QueryExecutor.ExecuteSelect(tx.AccountBalanceQuery.GetAccountBalanceByAccountID(senderID)) + rows, err = tx.QueryExecutor.ExecuteSelect(tx.AccountBalanceQuery.GetAccountBalanceByAccountAddress(tx.SenderAddress)) if err != nil { return err } else if rows.Next() { _ = rows.Scan( - &accountBalance.AccountID, + &accountBalance.AccountAddress, &accountBalance.BlockHeight, &accountBalance.SpendableBalance, &accountBalance.Balance, diff --git a/common/transaction/sendMoney.go b/common/transaction/sendMoney.go index b176d3d43..81c9d93a3 100644 --- a/common/transaction/sendMoney.go +++ b/common/transaction/sendMoney.go @@ -3,7 +3,6 @@ package transaction import ( "bytes" "errors" - "fmt" "github.com/zoobc/zoobc-core/common/constant" "github.com/zoobc/zoobc-core/common/query" @@ -14,16 +13,15 @@ import ( // SendMoney is Transaction Type that implemented TypeAction type SendMoney struct { - Body *model.SendMoneyTransactionBody - Fee int64 - SenderAddress string - SenderAccountType uint32 - RecipientAddress string - RecipientAccountType uint32 - Height uint32 - AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface - QueryExecutor query.ExecutorInterface + Body *model.SendMoneyTransactionBody + Fee int64 + SenderAccountAddressLength uint32 + SenderAddress string + RecipientAccountAddressLength uint32 + RecipientAddress string + Height uint32 + AccountBalanceQuery query.AccountBalanceQueryInterface + QueryExecutor query.ExecutorInterface } /* @@ -38,9 +36,7 @@ __If Not Genesis__: */ func (tx *SendMoney) ApplyConfirmed() error { var ( - recipientAccount model.Account - senderAccount model.Account - err error + err error ) if err := tx.Validate(); err != nil { @@ -54,37 +50,23 @@ func (tx *SendMoney) ApplyConfirmed() error { } } - recipientAccount = model.Account{ - ID: util.CreateAccountIDFromAddress(tx.RecipientAccountType, tx.RecipientAddress), - AccountType: tx.RecipientAccountType, - Address: tx.RecipientAddress, - } - senderAccount = model.Account{ - ID: util.CreateAccountIDFromAddress(tx.SenderAccountType, tx.SenderAddress), - AccountType: tx.SenderAccountType, - Address: tx.SenderAddress, - } - // insert / update recipient - recipientAccountInsertQ, recipientAccountInsertArgs := tx.AccountQuery.InsertAccount(&recipientAccount) accountBalanceRecipientQ := tx.AccountBalanceQuery.AddAccountBalance( tx.Body.Amount, map[string]interface{}{ - "account_id": recipientAccount.ID, - "block_height": tx.Height, + "account_address": tx.RecipientAddress, + "block_height": tx.Height, }, ) // update sender accountBalanceSenderQ := tx.AccountBalanceQuery.AddAccountBalance( -(tx.Body.Amount + tx.Fee), map[string]interface{}{ - "account_id": senderAccount.ID, - "block_height": tx.Height, + "account_address": tx.SenderAddress, + "block_height": tx.Height, }, ) - queries := append(append(accountBalanceRecipientQ, accountBalanceSenderQ...), - append([]interface{}{recipientAccountInsertQ}, recipientAccountInsertArgs...), - ) + queries := append(accountBalanceRecipientQ, accountBalanceSenderQ...) err = tx.QueryExecutor.ExecuteTransactions(queries) if err != nil { @@ -107,10 +89,7 @@ func (tx *SendMoney) ApplyUnconfirmed() error { accountBalanceSenderQ, accountBalanceSenderQArgs := tx.AccountBalanceQuery.AddAccountSpendableBalance( -(tx.Body.Amount + tx.Fee), map[string]interface{}{ - "account_id": util.CreateAccountIDFromAddress( - tx.SenderAccountType, - tx.SenderAddress, - ), + "account_address": tx.SenderAddress, }, ) err = tx.QueryExecutor.ExecuteTransaction(accountBalanceSenderQ, accountBalanceSenderQArgs...) @@ -134,10 +113,7 @@ func (tx *SendMoney) UndoApplyUnconfirmed() error { accountBalanceSenderQ, accountBalanceSenderQArgs := tx.AccountBalanceQuery.AddAccountSpendableBalance( tx.Body.Amount+tx.Fee, map[string]interface{}{ - "account_id": util.CreateAccountIDFromAddress( - tx.SenderAccountType, - tx.SenderAddress, - ), + "account_address": tx.SenderAddress, }, ) err = tx.QueryExecutor.ExecuteTransaction(accountBalanceSenderQ, accountBalanceSenderQArgs...) @@ -157,9 +133,7 @@ That specs: func (tx *SendMoney) Validate() error { var ( - err error accountBalance model.AccountBalance - count int ) if tx.Body.GetAmount() <= 0 { @@ -174,27 +148,13 @@ func (tx *SendMoney) Validate() error { return errors.New("transaction must have a valid sender account id") } - accounts, accountArgs := tx.AccountQuery.GetAccountByIDs([][]byte{ - util.CreateAccountIDFromAddress(tx.SenderAccountType, tx.SenderAddress), - util.CreateAccountIDFromAddress(tx.RecipientAccountType, tx.RecipientAddress), - }) - - err = tx.QueryExecutor.ExecuteSelectRow(query.GetTotalRecordOfSelect(accounts), accountArgs...).Scan(&count) - if err != nil { - return err - } - - if count <= 1 { - return fmt.Errorf("count recipient and sender got: %d", count) - } - senderID := util.CreateAccountIDFromAddress(tx.SenderAccountType, tx.SenderAddress) - senderQ, senderArg := tx.AccountBalanceQuery.GetAccountBalanceByAccountID(senderID) + senderQ, senderArg := tx.AccountBalanceQuery.GetAccountBalanceByAccountAddress(tx.SenderAddress) rows, err := tx.QueryExecutor.ExecuteSelect(senderQ, senderArg) if err != nil { return err } else if rows.Next() { _ = rows.Scan( - &accountBalance.AccountID, + &accountBalance.AccountAddress, &accountBalance.BlockHeight, &accountBalance.SpendableBalance, &accountBalance.Balance, diff --git a/common/transaction/transaction.go b/common/transaction/transaction.go index 306a73eed..5f9e78c5b 100644 --- a/common/transaction/transaction.go +++ b/common/transaction/transaction.go @@ -40,16 +40,15 @@ func (ts *TypeSwitcher) GetTransactionType(tx *model.Transaction) TypeAction { case 0: sendMoneyBody := new(SendMoney).ParseBodyBytes(tx.TransactionBodyBytes) return &SendMoney{ - Body: sendMoneyBody.(*model.SendMoneyTransactionBody), - Fee: tx.Fee, - SenderAddress: tx.GetSenderAccountAddress(), - SenderAccountType: tx.GetSenderAccountType(), - RecipientAddress: tx.GetRecipientAccountAddress(), - RecipientAccountType: tx.GetRecipientAccountType(), - Height: tx.GetHeight(), - AccountQuery: query.NewAccountQuery(), - AccountBalanceQuery: query.NewAccountBalanceQuery(), - QueryExecutor: ts.Executor, + Body: sendMoneyBody.(*model.SendMoneyTransactionBody), + Fee: tx.Fee, + SenderAddress: tx.GetSenderAccountAddress(), + SenderAccountAddressLength: tx.GetSenderAccountAddressLength(), + RecipientAddress: tx.GetRecipientAccountAddress(), + RecipientAccountAddressLength: tx.GetRecipientAccountAddressLength(), + Height: tx.GetHeight(), + AccountBalanceQuery: query.NewAccountBalanceQuery(), + QueryExecutor: ts.Executor, } default: return nil @@ -59,15 +58,14 @@ func (ts *TypeSwitcher) GetTransactionType(tx *model.Transaction) TypeAction { case 0: nodeRegistrationBody := new(NodeRegistration).ParseBodyBytes(tx.TransactionBodyBytes) return &NodeRegistration{ - Body: nodeRegistrationBody.(*model.NodeRegistrationTransactionBody), - Fee: tx.Fee, - SenderAddress: tx.GetSenderAccountAddress(), - SenderAccountType: tx.GetSenderAccountType(), - Height: tx.GetHeight(), - AccountQuery: query.NewAccountQuery(), - AccountBalanceQuery: query.NewAccountBalanceQuery(), - NodeRegistrationQuery: query.NewNodeRegistrationQuery(), - QueryExecutor: ts.Executor, + Body: nodeRegistrationBody.(*model.NodeRegistrationTransactionBody), + Fee: tx.Fee, + SenderAddress: tx.GetSenderAccountAddress(), + SenderAccountAddressLength: tx.GetSenderAccountAddressLength(), + Height: tx.GetHeight(), + AccountBalanceQuery: query.NewAccountBalanceQuery(), + NodeRegistrationQuery: query.NewNodeRegistrationQuery(), + QueryExecutor: ts.Executor, } default: return nil diff --git a/common/util/account.go b/common/util/account.go index 18c6e8a6d..a7dbfa483 100644 --- a/common/util/account.go +++ b/common/util/account.go @@ -2,7 +2,6 @@ package util import ( "encoding/base64" - "encoding/binary" "errors" "fmt" @@ -11,34 +10,6 @@ import ( "golang.org/x/crypto/sha3" ) -// CreateAccountIDFromAddress return the account ID byte which is the hash of -// account type (int32) and the account address (default: base64(public key)) -// for type 0 -func CreateAccountIDFromAddress(accountType uint32, address string) []byte { - digest := sha3.New256() - _, _ = digest.Write(ConvertUint32ToBytes(accountType)) - _, _ = digest.Write([]byte(address)) - accountID := digest.Sum([]byte{}) - return accountID -} - -// GetAccountIDByPublicKey return the account ID byte which is the hash of -// account type (uint32) and the account address (default: base64(public key)) -// for type 0 -func GetAccountIDByPublicKey(accountType uint32, publicKey []byte) []byte { - accountTypeByte := make([]byte, 4) - binary.LittleEndian.PutUint32(accountTypeByte, accountType) - var address string - if accountType == 0 { // default account type: zoobc - address, _ = GetAddressFromPublicKey(publicKey) - } - digest := sha3.New256() - _, _ = 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 @@ -96,17 +67,3 @@ func GetChecksumByte(bytes []byte) byte { } return a } - -// ValidateAccountAddress validates account address giving its account type -func ValidateAccountAddress(accType uint32, address string) error { - switch accType { - case 0: - pubKey, err := GetPublicKeyFromAddress(address) - if err != nil || len(pubKey) != 32 { - return errors.New("InvalidAccountAddress") - } - default: - return errors.New("InvalidAccountType") - } - return nil -} diff --git a/common/util/nodeRegistration.go b/common/util/nodeRegistration.go index 760d001df..29edc3b91 100644 --- a/common/util/nodeRegistration.go +++ b/common/util/nodeRegistration.go @@ -9,7 +9,7 @@ import ( // GetProofOfOwnershipSize returns size in bytes of a proof of ownership message func GetProofOfOwnershipSize(withSignature bool) uint32 { - message := constant.AccountType + constant.AccountAddress + constant.BlockHash + constant.Height + message := constant.AccountAddressLength + constant.AccountAddress + constant.BlockHash + constant.Height if withSignature { return message + constant.NodeSignature } @@ -51,7 +51,7 @@ func GetProofOfOwnershipMessageBytes(poownMessage *model.ProofOfOwnershipMessage // ParseProofOfOwnershipMessageBytes parse a byte array into a ProofOfOwnershipMessage struct (only the message, no signature) func ParseProofOfOwnershipMessageBytes(poownMessageBytes []byte) *model.ProofOfOwnershipMessage { buffer := bytes.NewBuffer(poownMessageBytes) - accountType := ConvertBytesToUint32(buffer.Next(int(constant.AccountType))) + accountType := ConvertBytesToUint32(buffer.Next(int(constant.AccountAddressLength))) accountAddress := buffer.Next(int(constant.AccountAddress)) blockHash := buffer.Next(int(constant.BlockHash)) height := ConvertBytesToUint32(buffer.Next(int(constant.Height))) diff --git a/common/util/transaction.go b/common/util/transaction.go index be8018249..ffc220da2 100644 --- a/common/util/transaction.go +++ b/common/util/transaction.go @@ -18,9 +18,9 @@ func GetTransactionBytes(transaction *model.Transaction, sign bool) ([]byte, err buffer.Write(ConvertUint32ToBytes(transaction.TransactionType)) buffer.Write(ConvertUint32ToBytes(transaction.Version)[:constant.TransactionVersion]) buffer.Write(ConvertUint64ToBytes(uint64(transaction.Timestamp))) - buffer.Write(ConvertUint32ToBytes(transaction.SenderAccountType)) + buffer.Write(ConvertUint32ToBytes(transaction.SenderAccountAddressLength)) buffer.Write([]byte(transaction.SenderAccountAddress)) - buffer.Write(ConvertUint32ToBytes(transaction.RecipientAccountType)) + buffer.Write(ConvertUint32ToBytes(transaction.RecipientAccountAddressLength)) if transaction.RecipientAccountAddress == "" { buffer.Write(make([]byte, constant.AccountAddress)) // if no recipient pad with 44 (zoobc address length) } else { @@ -58,16 +58,16 @@ func ParseTransactionBytes(transactionBytes []byte, sign bool) (*model.Transacti return nil, err } timestamp := ConvertBytesToUint64(timestampBytes) - senderAccountType, err := ReadTransactionBytes(buffer, int(constant.AccountType)) + senderAccountAddressLength, err := ReadTransactionBytes(buffer, int(constant.AccountAddressLength)) if err != nil { return nil, err } - senderAccountAddress := ReadAccountAddress(ConvertBytesToUint32(senderAccountType), buffer) - recipientAccountType, err := ReadTransactionBytes(buffer, int(constant.AccountType)) + senderAccountAddress := ReadAccountAddress(ConvertBytesToUint32(senderAccountAddressLength), buffer) + recipientAccountAddressLength, err := ReadTransactionBytes(buffer, int(constant.AccountAddressLength)) if err != nil { return nil, err } - recipientAccountAddress := ReadAccountAddress(ConvertBytesToUint32(recipientAccountType), buffer) + recipientAccountAddress := ReadAccountAddress(ConvertBytesToUint32(recipientAccountAddressLength), buffer) feeBytes, err := ReadTransactionBytes(buffer, int(constant.Fee)) if err != nil { return nil, err @@ -101,19 +101,19 @@ func ParseTransactionBytes(transactionBytes []byte, sign bool) (*model.Transacti transactionHash := sha3.Sum256(transactionBytes) txID, _ := GetTransactionID(transactionHash[:]) tx := &model.Transaction{ - ID: txID, - TransactionType: transactionType, - Version: transactionVersion, - Timestamp: int64(timestamp), - SenderAccountType: ConvertBytesToUint32(senderAccountType), - SenderAccountAddress: string(senderAccountAddress), - RecipientAccountType: ConvertBytesToUint32(recipientAccountType), - RecipientAccountAddress: string(recipientAccountAddress), - Fee: int64(fee), - TransactionBodyLength: transactionBodyLength, - TransactionBodyBytes: transactionBodyBytes, - TransactionHash: transactionHash[:], - Signature: sig, + ID: txID, + TransactionType: transactionType, + Version: transactionVersion, + Timestamp: int64(timestamp), + SenderAccountAddressLength: ConvertBytesToUint32(senderAccountAddressLength), + SenderAccountAddress: string(senderAccountAddress), + RecipientAccountAddressLength: ConvertBytesToUint32(recipientAccountAddressLength), + RecipientAccountAddress: string(recipientAccountAddress), + Fee: int64(fee), + TransactionBodyLength: transactionBodyLength, + TransactionBodyBytes: transactionBodyBytes, + TransactionHash: transactionHash[:], + Signature: sig, } return tx, nil } @@ -154,18 +154,9 @@ func ValidateTransaction( if tx.SenderAccountAddress == "" { return errors.New("TxSenderEmpty") } - if err := ValidateAccountAddress(tx.SenderAccountType, tx.SenderAccountAddress); err != nil { - return err - } - if tx.RecipientAccountAddress != "" { - if err := ValidateAccountAddress(tx.RecipientAccountType, tx.RecipientAccountAddress); err != nil { - return err - } - } // validate sender account - senderAccountID := CreateAccountIDFromAddress(tx.SenderAccountType, tx.SenderAccountAddress) - sqlQ, arg := accountBalanceQuery.GetAccountBalanceByAccountID(senderAccountID) + sqlQ, arg := accountBalanceQuery.GetAccountBalanceByAccountAddress(tx.SenderAccountAddress) rows, err := queryExecutor.ExecuteSelect(sqlQ, arg) if err != nil { return err From 923ec8882010729e9178ea7775a510d3ac15af45 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 12:43:20 +0800 Subject: [PATCH 02/27] #134 omit account type --- common/model/accountBalance.pb.go | 72 ++++++------ common/model/block.pb.go | 117 +++++++++++--------- common/model/mempool.pb.go | 74 ++++++------- common/model/nodeRegistration.pb.go | 122 ++++++++------------- common/model/transaction.pb.go | 157 ++++++++++++++------------- core/service/blockCoreService.go | 89 +++++++-------- core/service/genesisCoreService.go | 30 ++--- core/service/mempoolCoreService.go | 29 ++--- core/service/nodeAdminCoreService.go | 3 - core/smith/blockchainProcessor.go | 34 +++--- core/util/blockUtil.go | 3 +- 11 files changed, 338 insertions(+), 392 deletions(-) diff --git a/common/model/accountBalance.pb.go b/common/model/accountBalance.pb.go index 7cc3ad630..bb6f434f8 100644 --- a/common/model/accountBalance.pb.go +++ b/common/model/accountBalance.pb.go @@ -22,7 +22,7 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // AccountBalance represent the transaction data structure stored in the database type AccountBalance struct { - AccountID []byte `protobuf:"bytes,1,opt,name=AccountID,proto3" json:"AccountID,omitempty"` + AccountAddress string `protobuf:"bytes,1,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` BlockHeight uint32 `protobuf:"varint,2,opt,name=BlockHeight,proto3" json:"BlockHeight,omitempty"` SpendableBalance int64 `protobuf:"varint,3,opt,name=SpendableBalance,proto3" json:"SpendableBalance,omitempty"` Balance int64 `protobuf:"varint,4,opt,name=Balance,proto3" json:"Balance,omitempty"` @@ -58,11 +58,11 @@ func (m *AccountBalance) XXX_DiscardUnknown() { var xxx_messageInfo_AccountBalance proto.InternalMessageInfo -func (m *AccountBalance) GetAccountID() []byte { +func (m *AccountBalance) GetAccountAddress() string { if m != nil { - return m.AccountID + return m.AccountAddress } - return nil + return "" } func (m *AccountBalance) GetBlockHeight() uint32 { @@ -102,8 +102,7 @@ func (m *AccountBalance) GetLatest() bool { type GetAccountBalanceRequest struct { // Fetch AccountBalance by type/address - AccountType uint32 `protobuf:"varint,1,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,2,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + AccountAddress string `protobuf:"bytes,1,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -134,13 +133,6 @@ func (m *GetAccountBalanceRequest) XXX_DiscardUnknown() { var xxx_messageInfo_GetAccountBalanceRequest proto.InternalMessageInfo -func (m *GetAccountBalanceRequest) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *GetAccountBalanceRequest) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -341,32 +333,30 @@ func init() { func init() { proto.RegisterFile("model/accountBalance.proto", fileDescriptor_44b9b1c521a5bcaa) } var fileDescriptor_44b9b1c521a5bcaa = []byte{ - // 417 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xd1, 0xae, 0x93, 0x40, - 0x10, 0x86, 0xc3, 0xe1, 0x94, 0xe3, 0x99, 0x63, 0x4d, 0xdd, 0x44, 0x43, 0xab, 0x31, 0x84, 0x0b, - 0x43, 0x1a, 0x85, 0x44, 0x6f, 0xd5, 0xd8, 0xc6, 0xc4, 0x9a, 0xf4, 0xc2, 0x6c, 0x7b, 0xd5, 0x3b, - 0x58, 0x26, 0x85, 0x08, 0x2c, 0xc2, 0xa2, 0xb1, 0xaf, 0xe0, 0x03, 0xf8, 0x56, 0x3e, 0x93, 0xe9, - 0x76, 0xb1, 0x14, 0x68, 0x73, 0x6e, 0x48, 0xf6, 0xfb, 0xff, 0x99, 0xd9, 0xd9, 0x19, 0x60, 0x92, - 0xf2, 0x10, 0x13, 0xcf, 0x67, 0x8c, 0x57, 0x99, 0x98, 0xfb, 0x89, 0x9f, 0x31, 0x74, 0xf3, 0x82, - 0x0b, 0x4e, 0x06, 0x52, 0xb3, 0xff, 0x6a, 0xf0, 0x68, 0x76, 0xa2, 0x93, 0xe7, 0x70, 0xab, 0xc8, - 0x97, 0x4f, 0xa6, 0x66, 0x69, 0xce, 0x43, 0x7a, 0x04, 0xc4, 0x82, 0xbb, 0x79, 0xc2, 0xd9, 0xb7, - 0x05, 0xc6, 0xdb, 0x48, 0x98, 0x57, 0x96, 0xe6, 0x0c, 0x69, 0x13, 0x91, 0x29, 0x8c, 0x56, 0x39, - 0x66, 0xa1, 0x1f, 0x24, 0xa8, 0x72, 0x9a, 0xba, 0xa5, 0x39, 0x3a, 0xed, 0x70, 0x62, 0xc2, 0x4d, - 0x6d, 0xb9, 0x96, 0x96, 0xfa, 0x48, 0x5e, 0x00, 0x7c, 0xe5, 0x39, 0xc5, 0x1f, 0x98, 0x55, 0x68, - 0x0e, 0xa4, 0xd8, 0x20, 0xe4, 0x29, 0x18, 0x4b, 0x5f, 0x60, 0x29, 0x4c, 0xc3, 0xd2, 0x9c, 0x07, - 0x54, 0x9d, 0xec, 0x10, 0xcc, 0xcf, 0x28, 0x4e, 0x5b, 0xa2, 0xf8, 0xbd, 0xc2, 0x52, 0xec, 0xef, - 0xae, 0x84, 0xf5, 0xaf, 0x1c, 0x65, 0x6f, 0x43, 0xda, 0x44, 0xe4, 0xe5, 0xff, 0xd7, 0x98, 0x85, - 0x61, 0x81, 0x65, 0x29, 0x1b, 0xbc, 0xa5, 0x2d, 0x6a, 0x6f, 0x60, 0xdc, 0x53, 0xa5, 0xcc, 0x79, - 0x56, 0x22, 0x79, 0xdf, 0x7e, 0x52, 0x59, 0xe9, 0xee, 0xcd, 0x13, 0x57, 0xbe, 0xb9, 0xdb, 0x0a, - 0x6b, 0x99, 0xed, 0x3f, 0x7a, 0x4f, 0xf2, 0xb2, 0xee, 0x61, 0x0a, 0x23, 0x85, 0x96, 0xfc, 0x27, - 0x16, 0xeb, 0xc8, 0xcf, 0x54, 0x23, 0x1d, 0x4e, 0x5e, 0xc1, 0x63, 0xc5, 0x16, 0xf1, 0x36, 0x52, - 0xe6, 0xc3, 0xc4, 0xba, 0x02, 0x79, 0x07, 0xe3, 0xf6, 0x7c, 0x8e, 0x25, 0x74, 0x19, 0x75, 0xde, - 0x40, 0x3e, 0xc0, 0xa4, 0x2d, 0x36, 0x8a, 0x5e, 0xcb, 0xf0, 0x0b, 0x8e, 0x7d, 0xfc, 0x71, 0xba, - 0x9d, 0xf2, 0x83, 0x43, 0xfc, 0x79, 0x07, 0xf9, 0x08, 0xcf, 0x3a, 0x6a, 0xe3, 0x02, 0x86, 0x4c, - 0x70, 0xc9, 0xd2, 0xde, 0xec, 0x9b, 0xce, 0x66, 0xdb, 0xbf, 0x35, 0x98, 0xf4, 0x4d, 0x46, 0xcd, - 0xdd, 0x05, 0x72, 0x2a, 0xad, 0xe2, 0x5d, 0xbd, 0x65, 0x3d, 0x4a, 0xcf, 0x9e, 0x5c, 0x59, 0xfa, - 0xbd, 0xf7, 0x64, 0x3e, 0xdd, 0x38, 0xdb, 0x58, 0x44, 0x55, 0xe0, 0x32, 0x9e, 0x7a, 0x3b, 0xce, - 0x03, 0x76, 0xf8, 0xbe, 0x66, 0xbc, 0x40, 0x8f, 0xf1, 0x34, 0xe5, 0x99, 0x27, 0x53, 0x05, 0x86, - 0xfc, 0xe9, 0xdf, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x49, 0x83, 0x70, 0x94, 0x12, 0x04, 0x00, - 0x00, + // 395 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xc1, 0x6e, 0x9b, 0x40, + 0x10, 0x15, 0xc6, 0xc6, 0xed, 0x58, 0xae, 0xdc, 0x95, 0x5a, 0x61, 0x57, 0xaa, 0x10, 0x87, 0x0a, + 0x59, 0x2d, 0x48, 0xcd, 0x35, 0x89, 0x62, 0x2e, 0xf1, 0xc1, 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0x06, 0xff, 0x7f, 0x98, 0x62, 0xb6, 0x66, 0xad, 0xac, 0x26, 0xd6, 0x5f, 0xe5, 0x16, 0xf3, + 0x7c, 0x77, 0xc3, 0x29, 0x8c, 0x4a, 0x68, 0xc1, 0x9e, 0x31, 0xbb, 0x0f, 0xdc, 0x44, 0xd8, 0x0f, + 0x9d, 0x06, 0x4e, 0xfe, 0xc2, 0xf7, 0x12, 0x9b, 0x87, 0xeb, 0xa0, 0x14, 0x6f, 0xf3, 0x68, 0x12, + 0xe4, 0x12, 0xc6, 0xf5, 0xe9, 0xef, 0x5b, 0xc8, 0xa2, 0xea, 0xb8, 0x80, 0x5c, 0xc3, 0xa4, 0x4e, + 0x56, 0x9a, 0x76, 0x45, 0xf9, 0x09, 0xc5, 0x47, 0xfd, 0x3e, 0xbb, 0x46, 0xfb, 0xde, 0xb6, 0xfe, + 0xb8, 0x82, 0xdc, 0xc0, 0xaf, 0x06, 0x5b, 0xb9, 0x80, 0x22, 0x0c, 0x4e, 0x49, 0xea, 0x7b, 0xdb, + 0x6f, 0xec, 0xad, 0xfe, 0x22, 0xc1, 0xa4, 0x2d, 0x99, 0x32, 0x77, 0x13, 0xc8, 0x21, 0xb5, 0x0c, + 0x37, 0x58, 0x86, 0xd3, 0xc2, 0xb4, 0xec, 0x49, 0x47, 0x93, 0xcf, 0xde, 0x13, 0x7b, 0xba, 0x32, + 0xd6, 0x21, 0x0f, 0x0a, 0xcf, 0xa4, 0x2c, 0xb6, 0x36, 0x8c, 0x79, 0x74, 0xfb, 0xfd, 0x47, 0x59, + 0x86, 0x16, 0x65, 0x71, 0xcc, 0x12, 0x4b, 0x58, 0x79, 0x8a, 0xf8, 0xb9, 0x2f, 0xde, 0x03, 0x00, + 0x00, 0xff, 0xff, 0x14, 0x15, 0x28, 0xbf, 0xfa, 0x03, 0x00, 0x00, } diff --git a/common/model/block.pb.go b/common/model/block.pb.go index 05ff7fff6..f45278c57 100644 --- a/common/model/block.pb.go +++ b/common/model/block.pb.go @@ -22,25 +22,26 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Block represent the block data structure stored in the database type Block struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - PreviousBlockHash []byte `protobuf:"bytes,2,opt,name=PreviousBlockHash,proto3" json:"PreviousBlockHash,omitempty"` - Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` - Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` - BlockSeed []byte `protobuf:"bytes,5,opt,name=BlockSeed,proto3" json:"BlockSeed,omitempty"` - BlockSignature []byte `protobuf:"bytes,6,opt,name=BlockSignature,proto3" json:"BlockSignature,omitempty"` - CumulativeDifficulty string `protobuf:"bytes,7,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` - SmithScale int64 `protobuf:"varint,8,opt,name=SmithScale,proto3" json:"SmithScale,omitempty"` - BlocksmithID []byte `protobuf:"bytes,9,opt,name=BlocksmithID,proto3" json:"BlocksmithID,omitempty"` - TotalAmount int64 `protobuf:"varint,10,opt,name=TotalAmount,proto3" json:"TotalAmount,omitempty"` - TotalFee int64 `protobuf:"varint,11,opt,name=TotalFee,proto3" json:"TotalFee,omitempty"` - TotalCoinBase int64 `protobuf:"varint,12,opt,name=TotalCoinBase,proto3" json:"TotalCoinBase,omitempty"` - Version uint32 `protobuf:"varint,13,opt,name=Version,proto3" json:"Version,omitempty"` - PayloadLength uint32 `protobuf:"varint,14,opt,name=PayloadLength,proto3" json:"PayloadLength,omitempty"` - PayloadHash []byte `protobuf:"bytes,15,opt,name=PayloadHash,proto3" json:"PayloadHash,omitempty"` - Transactions []*Transaction `protobuf:"bytes,16,rep,name=Transactions,proto3" json:"Transactions,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` + PreviousBlockHash []byte `protobuf:"bytes,2,opt,name=PreviousBlockHash,proto3" json:"PreviousBlockHash,omitempty"` + Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` + Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` + BlockSeed []byte `protobuf:"bytes,5,opt,name=BlockSeed,proto3" json:"BlockSeed,omitempty"` + BlockSignature []byte `protobuf:"bytes,6,opt,name=BlockSignature,proto3" json:"BlockSignature,omitempty"` + CumulativeDifficulty string `protobuf:"bytes,7,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` + SmithScale int64 `protobuf:"varint,8,opt,name=SmithScale,proto3" json:"SmithScale,omitempty"` + BlocksmithAddressLength uint32 `protobuf:"varint,9,opt,name=BlocksmithAddressLength,proto3" json:"BlocksmithAddressLength,omitempty"` + BlocksmithAddress string `protobuf:"bytes,10,opt,name=BlocksmithAddress,proto3" json:"BlocksmithAddress,omitempty"` + TotalAmount int64 `protobuf:"varint,11,opt,name=TotalAmount,proto3" json:"TotalAmount,omitempty"` + TotalFee int64 `protobuf:"varint,12,opt,name=TotalFee,proto3" json:"TotalFee,omitempty"` + TotalCoinBase int64 `protobuf:"varint,13,opt,name=TotalCoinBase,proto3" json:"TotalCoinBase,omitempty"` + Version uint32 `protobuf:"varint,14,opt,name=Version,proto3" json:"Version,omitempty"` + PayloadLength uint32 `protobuf:"varint,15,opt,name=PayloadLength,proto3" json:"PayloadLength,omitempty"` + PayloadHash []byte `protobuf:"bytes,16,opt,name=PayloadHash,proto3" json:"PayloadHash,omitempty"` + Transactions []*Transaction `protobuf:"bytes,17,rep,name=Transactions,proto3" json:"Transactions,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Block) Reset() { *m = Block{} } @@ -124,11 +125,18 @@ func (m *Block) GetSmithScale() int64 { return 0 } -func (m *Block) GetBlocksmithID() []byte { +func (m *Block) GetBlocksmithAddressLength() uint32 { if m != nil { - return m.BlocksmithID + return m.BlocksmithAddressLength } - return nil + return 0 +} + +func (m *Block) GetBlocksmithAddress() string { + if m != nil { + return m.BlocksmithAddress + } + return "" } func (m *Block) GetTotalAmount() int64 { @@ -375,36 +383,37 @@ func init() { func init() { proto.RegisterFile("model/block.proto", fileDescriptor_baa78346dbb08dbe) } var fileDescriptor_baa78346dbb08dbe = []byte{ - // 493 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x5d, 0x6b, 0x13, 0x41, - 0x14, 0x65, 0xd3, 0x24, 0x6d, 0x6e, 0x3e, 0xda, 0x0c, 0x45, 0x87, 0x22, 0xb2, 0x84, 0x22, 0x8b, - 0x68, 0x02, 0x15, 0x7c, 0x37, 0x09, 0xda, 0x40, 0x1f, 0xca, 0x26, 0x28, 0xf8, 0x20, 0x4c, 0x36, - 0xb7, 0xd9, 0xc1, 0x9d, 0x99, 0xb8, 0x33, 0x5b, 0x88, 0xef, 0xfe, 0x26, 0xff, 0x9e, 0xec, 0xdd, - 0x6d, 0xb3, 0x51, 0x83, 0xbe, 0x84, 0x9c, 0x73, 0xee, 0x9c, 0x3b, 0x7b, 0xef, 0x19, 0xe8, 0x2b, - 0xb3, 0xc2, 0x64, 0xb4, 0x4c, 0x4c, 0xf4, 0x75, 0xb8, 0x49, 0x8d, 0x33, 0xac, 0x41, 0xd4, 0xc5, - 0xd3, 0x42, 0x71, 0xa9, 0xd0, 0x56, 0x44, 0x4e, 0x1a, 0x5d, 0xe8, 0x83, 0x9f, 0x75, 0x68, 0x8c, - 0xf3, 0x7a, 0xd6, 0x83, 0xda, 0x6c, 0xca, 0x3d, 0xdf, 0x0b, 0x8e, 0xc2, 0xda, 0x6c, 0xca, 0x5e, - 0x41, 0xff, 0x36, 0xc5, 0x7b, 0x69, 0x32, 0x4b, 0x05, 0xd7, 0xc2, 0xc6, 0xbc, 0xe6, 0x7b, 0x41, - 0x27, 0xfc, 0x53, 0x60, 0x4f, 0xa0, 0x79, 0x8d, 0x72, 0x1d, 0x3b, 0x7e, 0xe4, 0x7b, 0x41, 0x37, - 0x2c, 0x11, 0x7b, 0x06, 0xad, 0x85, 0x54, 0x68, 0x9d, 0x50, 0x1b, 0x5e, 0x27, 0xf3, 0x1d, 0x91, - 0xab, 0x64, 0x31, 0x47, 0x5c, 0xf1, 0x06, 0x79, 0xef, 0x08, 0xf6, 0x02, 0x7a, 0x05, 0x90, 0x6b, - 0x2d, 0x5c, 0x96, 0x22, 0x6f, 0x52, 0xc9, 0x6f, 0x2c, 0xbb, 0x82, 0xf3, 0x49, 0xa6, 0xb2, 0x44, - 0x38, 0x79, 0x8f, 0x53, 0x79, 0x77, 0x27, 0xa3, 0x2c, 0x71, 0x5b, 0x7e, 0xec, 0x7b, 0x41, 0x2b, - 0xfc, 0xab, 0xc6, 0x9e, 0x03, 0xcc, 0x95, 0x74, 0xf1, 0x3c, 0x12, 0x09, 0xf2, 0x13, 0xba, 0x58, - 0x85, 0x61, 0x03, 0xe8, 0x50, 0x17, 0x9b, 0x53, 0xb3, 0x29, 0x6f, 0x51, 0xe7, 0x3d, 0x8e, 0xf9, - 0xd0, 0x5e, 0x18, 0x27, 0x92, 0x77, 0xca, 0x64, 0xda, 0x71, 0x20, 0x93, 0x2a, 0xc5, 0x2e, 0xe0, - 0x84, 0xe0, 0x7b, 0x44, 0xde, 0x26, 0xf9, 0x11, 0xb3, 0x4b, 0xe8, 0xd2, 0xff, 0x89, 0x91, 0x7a, - 0x2c, 0x2c, 0xf2, 0x0e, 0x15, 0xec, 0x93, 0x8c, 0xc3, 0xf1, 0x47, 0x4c, 0xad, 0x34, 0x9a, 0x77, - 0x69, 0xb0, 0x0f, 0x30, 0x3f, 0x7f, 0x2b, 0xb6, 0x89, 0x11, 0xab, 0x1b, 0xd4, 0x6b, 0x17, 0xf3, - 0x1e, 0xe9, 0xfb, 0x64, 0x7e, 0xc7, 0x92, 0xa0, 0xfd, 0x9d, 0xd2, 0x67, 0x54, 0x29, 0xf6, 0x16, - 0x3a, 0x8b, 0x5d, 0x2c, 0x2c, 0x3f, 0xf3, 0x8f, 0x82, 0xf6, 0x15, 0x1b, 0x52, 0x62, 0x86, 0x15, - 0x29, 0xdc, 0xab, 0x1b, 0x7c, 0x82, 0xd3, 0x0f, 0xe8, 0x68, 0x20, 0x21, 0x7e, 0xcb, 0xd0, 0xd2, - 0xb2, 0x27, 0xb1, 0x90, 0x7a, 0xb1, 0xdd, 0x20, 0x25, 0xa9, 0x11, 0xee, 0x88, 0x32, 0x60, 0xb5, - 0xc7, 0x80, 0x1d, 0x88, 0xcc, 0xe0, 0x0b, 0x9c, 0x3d, 0x18, 0xdb, 0xff, 0x73, 0x3e, 0x87, 0xc6, - 0x8d, 0x54, 0xd2, 0x91, 0x79, 0x37, 0x2c, 0xc0, 0x41, 0xff, 0x1f, 0x1e, 0xf4, 0x2b, 0x0d, 0xec, - 0xc6, 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa1, 0x25, 0x97, 0x1d, 0x08, 0x1c, 0x0c, 0xfd, 0x25, 0x34, - 0xe9, 0x0d, 0x5a, 0x5e, 0xa7, 0x61, 0x76, 0xca, 0x61, 0x16, 0xc3, 0x2a, 0xb5, 0xf1, 0xcb, 0xcf, - 0xc1, 0x5a, 0xba, 0x38, 0x5b, 0x0e, 0x23, 0xa3, 0x46, 0xdf, 0x8d, 0x59, 0x46, 0xc5, 0xef, 0xeb, - 0xc8, 0xa4, 0x38, 0x8a, 0x8c, 0x52, 0x46, 0x8f, 0xe8, 0xe4, 0xb2, 0x49, 0xaf, 0xf5, 0xcd, 0xaf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0xb2, 0xdb, 0x20, 0xe2, 0x03, 0x00, 0x00, + // 508 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00,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d5, 0xf5, 0x3e, 0xc3, 0xf1, 0x47, 0x74, 0xb4, 0x95, 0x10, 0xbf, 0x67, 0x68, 0x29, 0x30, + 0xa3, 0x58, 0x48, 0x3d, 0x5d, 0x2d, 0x91, 0xd2, 0x58, 0x0b, 0xd7, 0x44, 0x19, 0xd2, 0xca, 0x53, + 0x48, 0xf7, 0xc4, 0xae, 0xf7, 0x15, 0x4e, 0x1e, 0x8d, 0xed, 0xff, 0x39, 0x9f, 0x42, 0xed, 0x56, + 0x2a, 0xe9, 0xc8, 0xbc, 0x1d, 0x16, 0x60, 0xaf, 0xff, 0x4f, 0x0f, 0xba, 0x1b, 0x0d, 0xec, 0xd2, + 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa2, 0x4b, 0x2e, 0x3b, 0x10, 0xd8, 0xfb, 0x70, 0x2e, 0xa0, 0x4e, + 0xef, 0xd8, 0xf2, 0x2a, 0x2d, 0xb3, 0x55, 0x2e, 0xb3, 0x58, 0x56, 0xa9, 0x0d, 0x5f, 0x7d, 0x09, + 0x16, 0xd2, 0xc5, 0xd9, 0xac, 0x1f, 0x19, 0x35, 0xf8, 0x61, 0xcc, 0x2c, 0x2a, 0x7e, 0xdf, 0x44, + 0x26, 0xc5, 0x41, 0x64, 0x94, 0x32, 0x7a, 0x40, 0x5f, 0xce, 0xea, 0xf4, 0xe2, 0xdf, 0xfe, 0x0e, + 0x00, 0x00, 0xff, 0xff, 0x7c, 0x21, 0x8e, 0x1d, 0x26, 0x04, 0x00, 0x00, } diff --git a/common/model/mempool.pb.go b/common/model/mempool.pb.go index 63aeb3bf7..d185f95ab 100644 --- a/common/model/mempool.pb.go +++ b/common/model/mempool.pb.go @@ -22,15 +22,15 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Mempool represent the mempool data structure stored in the database type MempoolTransaction struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - FeePerByte int32 `protobuf:"varint,2,opt,name=FeePerByte,proto3" json:"FeePerByte,omitempty"` - ArrivalTimestamp int64 `protobuf:"varint,3,opt,name=ArrivalTimestamp,proto3" json:"ArrivalTimestamp,omitempty"` - TransactionBytes []byte `protobuf:"bytes,4,opt,name=TransactionBytes,proto3" json:"TransactionBytes,omitempty"` - SenderAccountID []byte `protobuf:"bytes,5,opt,name=SenderAccountID,proto3" json:"SenderAccountID,omitempty"` - RecipientAccountID []byte `protobuf:"bytes,6,opt,name=RecipientAccountID,proto3" json:"RecipientAccountID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` + FeePerByte int32 `protobuf:"varint,2,opt,name=FeePerByte,proto3" json:"FeePerByte,omitempty"` + ArrivalTimestamp int64 `protobuf:"varint,3,opt,name=ArrivalTimestamp,proto3" json:"ArrivalTimestamp,omitempty"` + TransactionBytes []byte `protobuf:"bytes,4,opt,name=TransactionBytes,proto3" json:"TransactionBytes,omitempty"` + SenderAccountAddress string `protobuf:"bytes,5,opt,name=SenderAccountAddress,proto3" json:"SenderAccountAddress,omitempty"` + RecipientAccountAddress string `protobuf:"bytes,6,opt,name=RecipientAccountAddress,proto3" json:"RecipientAccountAddress,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *MempoolTransaction) Reset() { *m = MempoolTransaction{} } @@ -86,18 +86,18 @@ func (m *MempoolTransaction) GetTransactionBytes() []byte { return nil } -func (m *MempoolTransaction) GetSenderAccountID() []byte { +func (m *MempoolTransaction) GetSenderAccountAddress() string { if m != nil { - return m.SenderAccountID + return m.SenderAccountAddress } - return nil + return "" } -func (m *MempoolTransaction) GetRecipientAccountID() []byte { +func (m *MempoolTransaction) GetRecipientAccountAddress() string { if m != nil { - return m.RecipientAccountID + return m.RecipientAccountAddress } - return nil + return "" } type GetMempoolTransactionRequest struct { @@ -248,26 +248,26 @@ func init() { func init() { proto.RegisterFile("model/mempool.proto", fileDescriptor_22ea31ac6d427b7b) } var fileDescriptor_22ea31ac6d427b7b = []byte{ - // 324 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xcf, 0x4a, 0xc3, 0x40, - 0x10, 0xc6, 0x49, 0xd2, 0xf6, 0x30, 0xf5, 0x1f, 0xdb, 0x4b, 0x04, 0x2d, 0x21, 0xa7, 0x50, 0x30, - 0x01, 0x7d, 0x82, 0xd6, 0x52, 0xa9, 0x22, 0x48, 0x9a, 0x93, 0xb7, 0x74, 0x3b, 0xe8, 0x42, 0x77, - 0x27, 0xee, 0x6e, 0x05, 0xfb, 0x12, 0xbe, 0xad, 0x67, 0xe9, 0xb6, 0x62, 0xb1, 0xeb, 0x25, 0x84, - 0x6f, 0xbe, 0xf9, 0xed, 0xcc, 0xb7, 0x0b, 0x3d, 0x49, 0x0b, 0x5c, 0x16, 0x12, 0x65, 0x43, 0xb4, - 0xcc, 0x1b, 0x4d, 0x96, 0x58, 0xdb, 0x89, 0xe9, 0x57, 0x00, 0xec, 0x71, 0x5b, 0xa8, 0x74, 0xad, - 0x4c, 0xcd, 0xad, 0x20, 0xc5, 0x4e, 0x20, 0x9c, 0x8e, 0xe3, 0x20, 0x09, 0xb2, 0xa8, 0x0c, 0xa7, - 0x63, 0xd6, 0x07, 0x98, 0x20, 0x3e, 0xa1, 0x1e, 0x7d, 0x58, 0x8c, 0xc3, 0x24, 0xc8, 0xda, 0xe5, - 0x9e, 0xc2, 0x06, 0x70, 0x36, 0xd4, 0x5a, 0xbc, 0xd7, 0xcb, 0x4a, 0x48, 0x34, 0xb6, 0x96, 0x4d, - 0x1c, 0xb9, 0xee, 0x03, 0x7d, 0xe3, 0xdd, 0x3b, 0x6a, 0xd3, 0x6e, 0xe2, 0x56, 0x12, 0x64, 0x47, - 0xe5, 0x81, 0xce, 0x32, 0x38, 0x9d, 0xa1, 0x5a, 0xa0, 0x1e, 0x72, 0x4e, 0x2b, 0x65, 0xa7, 0xe3, - 0xb8, 0xed, 0xac, 0x7f, 0x65, 0x96, 0x03, 0x2b, 0x91, 0x8b, 0x46, 0xa0, 0xb2, 0xbf, 0xe6, 0x8e, - 0x33, 0x7b, 0x2a, 0xe9, 0x3d, 0x5c, 0xdc, 0xa1, 0x3d, 0x5c, 0xbd, 0xc4, 0xb7, 0x15, 0x1a, 0xeb, - 0x9d, 0x32, 0xf0, 0x4f, 0x99, 0xde, 0xc2, 0xa5, 0x97, 0x65, 0x7e, 0x60, 0x0c, 0x5a, 0x13, 0x4d, - 0x72, 0x17, 0xa8, 0xfb, 0xdf, 0x44, 0x5c, 0x91, 0x8b, 0x32, 0x2a, 0xc3, 0x8a, 0xd2, 0xcf, 0x00, - 0xfa, 0xff, 0x51, 0x4c, 0x43, 0xca, 0x20, 0x4b, 0xa0, 0xbb, 0x2b, 0xcf, 0xc4, 0x1a, 0x1d, 0xed, - 0xb8, 0xdc, 0x97, 0xd8, 0x03, 0xf4, 0x3c, 0x80, 0x38, 0x4c, 0xa2, 0xac, 0x7b, 0x7d, 0x9e, 0xbb, - 0x3b, 0xcf, 0x3d, 0x4b, 0xfb, 0xba, 0x46, 0x83, 0xe7, 0xec, 0x45, 0xd8, 0xd7, 0xd5, 0x3c, 0xe7, - 0x24, 0x8b, 0x35, 0xd1, 0x9c, 0x6f, 0xbf, 0x57, 0x9c, 0x34, 0x16, 0x9c, 0xa4, 0x24, 0x55, 0x38, - 0xe6, 0xbc, 0xe3, 0x5e, 0xd5, 0xcd, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x97, 0x8a, 0xb5, - 0x6c, 0x02, 0x00, 0x00, + // 332 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x4b, 0xe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58, 0x9b, 0x5f, 0xb1, 0x8e, 0x8d, 0x1d, 0xb3, 0xe3, 0x7b, 0xb8, 0xb8, + 0x43, 0x73, 0x58, 0x07, 0xc7, 0xb7, 0x15, 0x6a, 0xe3, 0x9c, 0xdc, 0x73, 0x4f, 0x1e, 0xdf, 0xc2, + 0xa5, 0x93, 0xa5, 0x7f, 0x60, 0x0c, 0x5a, 0x53, 0x45, 0x72, 0x57, 0xb2, 0xfd, 0xdf, 0xd4, 0x9e, + 0x93, 0xad, 0x37, 0xe0, 0x7e, 0x4e, 0xf1, 0x97, 0x07, 0xfd, 0x63, 0x14, 0xdd, 0x50, 0xad, 0x91, + 0x45, 0xd0, 0xdd, 0xd9, 0xf3, 0x6a, 0x8d, 0x96, 0xf6, 0x8f, 0xef, 0x4b, 0xec, 0x01, 0x7a, 0x0e, + 0x40, 0xe8, 0x47, 0x41, 0xd2, 0x1d, 0x9e, 0xa7, 0x76, 0x0f, 0x52, 0xc7, 0xa3, 0x5d, 0xa9, 0xf1, + 0xe0, 0x39, 0x79, 0xa9, 0xcc, 0xeb, 0x6a, 0x91, 0x0a, 0x92, 0xd9, 0x9a, 0x68, 0x21, 0xb6, 0xdf, + 0x2b, 0x41, 0x0a, 0x33, 0x41, 0x52, 0x52, 0x9d, 0x59, 0xe6, 0xa2, 0x63, 0x37, 0xed, 0xfa, 0x3b, + 0x00, 0x00, 0xff, 0xff, 0xfb, 0x34, 0x78, 0xa7, 0x80, 0x02, 0x00, 0x00, } diff --git a/common/model/nodeRegistration.pb.go b/common/model/nodeRegistration.pb.go index 6615587f4..400be9747 100644 --- a/common/model/nodeRegistration.pb.go +++ b/common/model/nodeRegistration.pb.go @@ -23,7 +23,7 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type NodeRegistration struct { NodeID int64 `protobuf:"varint,1,opt,name=NodeID,proto3" json:"NodeID,omitempty"` NodePublicKey []byte `protobuf:"bytes,2,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountId []byte `protobuf:"bytes,3,opt,name=AccountId,proto3" json:"AccountId,omitempty"` + AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` NodeAddress string `protobuf:"bytes,5,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` LockedBalance int64 `protobuf:"varint,6,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` @@ -74,11 +74,11 @@ func (m *NodeRegistration) GetNodePublicKey() []byte { return nil } -func (m *NodeRegistration) GetAccountId() []byte { +func (m *NodeRegistration) GetAccountAddress() string { if m != nil { - return m.AccountId + return m.AccountAddress } - return nil + return "" } func (m *NodeRegistration) GetRegistrationHeight() uint32 { @@ -126,9 +126,8 @@ func (m *NodeRegistration) GetHeight() uint32 { // GetNodeRegisterRequest create request to get a list node type GetNodeRegistrationsRequest struct { NodePublicKey []byte `protobuf:"bytes,1,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,2,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` - RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` + AccountAddress string `protobuf:"bytes,2,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + RegistrationHeight uint32 `protobuf:"varint,3,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -166,13 +165,6 @@ func (m *GetNodeRegistrationsRequest) GetNodePublicKey() []byte { return nil } -func (m *GetNodeRegistrationsRequest) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *GetNodeRegistrationsRequest) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -190,10 +182,9 @@ func (m *GetNodeRegistrationsRequest) GetRegistrationHeight() uint32 { // GetNodeRegistrationRequest create request for single node register type GetNodeRegistrationRequest struct { NodePublicKey []byte `protobuf:"bytes,1,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,2,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` - RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` - NodeAddress string `protobuf:"bytes,5,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` + AccountAddress string `protobuf:"bytes,2,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + RegistrationHeight uint32 `protobuf:"varint,3,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` + NodeAddress string `protobuf:"bytes,4,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -231,13 +222,6 @@ func (m *GetNodeRegistrationRequest) GetNodePublicKey() []byte { return nil } -func (m *GetNodeRegistrationRequest) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *GetNodeRegistrationRequest) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -263,10 +247,9 @@ func (m *GetNodeRegistrationRequest) GetNodeAddress() string { type UpdateNodeRegistrationRequest struct { ID []byte `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` NodePublicKey []byte `protobuf:"bytes,2,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,3,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,4,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` - NodeAddress string `protobuf:"bytes,5,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` - LockedBalance int64 `protobuf:"varint,6,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` + AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + NodeAddress string `protobuf:"bytes,4,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` + LockedBalance int64 `protobuf:"varint,5,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -311,13 +294,6 @@ func (m *UpdateNodeRegistrationRequest) GetNodePublicKey() []byte { return nil } -func (m *UpdateNodeRegistrationRequest) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *UpdateNodeRegistrationRequest) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -342,14 +318,13 @@ func (m *UpdateNodeRegistrationRequest) GetLockedBalance() int64 { type GetNodeRegistrationsResponse struct { ID []byte `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` NodePublicKey []byte `protobuf:"bytes,2,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,3,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,4,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` - RegistrationHeight uint32 `protobuf:"varint,5,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` - NodeAddress string `protobuf:"bytes,6,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` - LockedBalance int64 `protobuf:"varint,7,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` - Queued bool `protobuf:"varint,8,opt,name=Queued,proto3" json:"Queued,omitempty"` - Latest bool `protobuf:"varint,9,opt,name=Latest,proto3" json:"Latest,omitempty"` - Height uint32 `protobuf:"varint,10,opt,name=Height,proto3" json:"Height,omitempty"` + AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` + NodeAddress string `protobuf:"bytes,5,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` + LockedBalance int64 `protobuf:"varint,6,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` + Queued bool `protobuf:"varint,7,opt,name=Queued,proto3" json:"Queued,omitempty"` + Latest bool `protobuf:"varint,8,opt,name=Latest,proto3" json:"Latest,omitempty"` + Height uint32 `protobuf:"varint,9,opt,name=Height,proto3" json:"Height,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -394,13 +369,6 @@ func (m *GetNodeRegistrationsResponse) GetNodePublicKey() []byte { return nil } -func (m *GetNodeRegistrationsResponse) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *GetNodeRegistrationsResponse) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -461,31 +429,29 @@ func init() { func init() { proto.RegisterFile("model/nodeRegistration.proto", fileDescriptor_df1af0ec89e31788) } var fileDescriptor_df1af0ec89e31788 = []byte{ - // 410 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x94, 0xdf, 0xca, 0xd3, 0x30, - 0x18, 0xc6, 0x49, 0xbb, 0x75, 0x6b, 0xf6, 0x07, 0xc9, 0x81, 0x04, 0x9d, 0x50, 0x8a, 0x48, 0x11, - 0x5c, 0x0f, 0xbc, 0x82, 0x0d, 0x41, 0x87, 0x43, 0x34, 0xe8, 0x89, 0x67, 0x6d, 0xf2, 0xb2, 0x15, - 0xd7, 0xa6, 0xb6, 0xe9, 0xc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to + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x94, 0xcf, 0x4a, 0xeb, 0x40, + 0x14, 0xc6, 0x99, 0xf4, 0xcf, 0x6d, 0xe7, 0xb6, 0xe5, 0x92, 0xc5, 0x65, 0xd0, 0x0a, 0x21, 0x88, + 0x04, 0xc1, 0x66, 0xe1, 0x13, 0xb4, 0x08, 0x2a, 0x16, 0xd1, 0x01, 0x37, 0xee, 0x92, 0x99, 0x43, + 0x1b, 0x6c, 0x72, 0x6a, 0x66, 0xb2, 0xd0, 0x57, 0xf1, 0x45, 0x5c, 0x74, 0xeb, 0x7b, 0xc9, 0xa4, + 0x11, 0xda, 0x34, 0x45, 0x05, 0x05, 0xdd, 0x84, 0x9c, 0xdf, 0x24, 0x33, 0xdf, 0xf9, 0xe6, 0x9b, + 0xa1, 0xfd, 0x18, 0x25, 0xcc, 0xfc, 0x04, 0x25, 0x70, 0x98, 0x44, 0x4a, 0xa7, 0x81, 0x8e, 0x30, + 0x19, 0xcc, 0x53, 0xd4, 0x68, 0x37, 0xf2, 0x51, 0xf7, 0xd9, 0xa2, 0xff, 0x2e, 0x4b, 0x5f, 0xd8, + 0xff, 0x69, 0xd3, 0xb0, 0xf3, 0x13, 0x46, 0x1c, 0xe2, 0xd5, 0x78, 0x51, 0xd9, 0xfb, 0xb4, 0x6b, + 0xde, 0xae, 0xb2, 0x70, 0x16, 0x89, 0x0b, 0x78, 0x60, 0x96, 0x43, 0xbc, 0x0e, 0x5f, 0x87, 0xf6, + 0x01, 0xed, 0x0d, 0x85, 0xc0, 0x2c, 0xd1, 0x43, 0x29, 0x53, 0x50, 0x8a, 0xd5, 0x1c, 0xe2, 0xb5, + 0x79, 0x89, 0xda, 0x03, 0x6a, 0xaf, 0xae, 0x7a, 0x06, 0xd1, 0x64, 0xaa, 0x59, 0xdd, 0x21, 0x5e, + 0x97, 0x57, 0x8c, 0xd8, 0x0e, 0xfd, 0x6b, 0x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xf8, 0x04, 0x00, + 0x00, } diff --git a/common/model/transaction.pb.go b/common/model/transaction.pb.go index 007a00f84..e0a8d23d4 100644 --- a/common/model/transaction.pb.go +++ b/common/model/transaction.pb.go @@ -22,20 +22,20 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Transaction represent the transaction data structure stored in the database type Transaction struct { - 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"` + 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"` + SenderAccountAddressLength uint32 `protobuf:"varint,5,opt,name=SenderAccountAddressLength,proto3" json:"SenderAccountAddressLength,omitempty"` + SenderAccountAddress string `protobuf:"bytes,6,opt,name=SenderAccountAddress,proto3" json:"SenderAccountAddress,omitempty"` + RecipientAccountAddressLength uint32 `protobuf:"varint,7,opt,name=RecipientAccountAddressLength,proto3" json:"RecipientAccountAddressLength,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: @@ -103,9 +103,9 @@ func (m *Transaction) GetHeight() uint32 { return 0 } -func (m *Transaction) GetSenderAccountType() uint32 { +func (m *Transaction) GetSenderAccountAddressLength() uint32 { if m != nil { - return m.SenderAccountType + return m.SenderAccountAddressLength } return 0 } @@ -117,9 +117,9 @@ func (m *Transaction) GetSenderAccountAddress() string { return "" } -func (m *Transaction) GetRecipientAccountType() uint32 { +func (m *Transaction) GetRecipientAccountAddressLength() uint32 { if m != nil { - return m.RecipientAccountType + return m.RecipientAccountAddressLength } return 0 } @@ -325,7 +325,7 @@ func (m *SendMoneyTransactionBody) GetAmount() int64 { type NodeRegistrationTransactionBody struct { NodePublicKey []byte `protobuf:"bytes,1,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,2,opt,name=AccountType,proto3" json:"AccountType,omitempty"` + AccountAddressLength uint32 `protobuf:"varint,2,opt,name=AccountAddressLength,proto3" json:"AccountAddressLength,omitempty"` AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` NodeAddressLength uint32 `protobuf:"varint,5,opt,name=NodeAddressLength,proto3" json:"NodeAddressLength,omitempty"` @@ -369,9 +369,9 @@ func (m *NodeRegistrationTransactionBody) GetNodePublicKey() []byte { return nil } -func (m *NodeRegistrationTransactionBody) GetAccountType() uint32 { +func (m *NodeRegistrationTransactionBody) GetAccountAddressLength() uint32 { if m != nil { - return m.AccountType + return m.AccountAddressLength } return 0 } @@ -943,61 +943,62 @@ func init() { func init() { proto.RegisterFile("model/transaction.proto", fileDescriptor_8333001f09b34082) } var fileDescriptor_8333001f09b34082 = []byte{ - // 895 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x5f, 0x6f, 0x1b, 0x45, - 0x10, 0xcf, 0xf9, 0xe2, 0xb4, 0x19, 0x3b, 0x69, 0xb2, 0xb8, 0xf1, 0x4a, 0x54, 0xc4, 0x9c, 0x68, - 0xb1, 0xaa, 0xd6, 0x91, 0x4c, 0x85, 0x78, 0x8d, 0x09, 0xc1, 0x11, 0x29, 0x31, 0x17, 0x97, 0x07, - 0x24, 0x1e, 0x2e, 0x77, 0x63, 0xfb, 0x54, 0xdf, 0xae, 0xb9, 0x5d, 0x53, 0x19, 0x89, 0x37, 0xf8, - 0x24, 0x88, 0xaf, 0xc6, 0x07, 0xe0, 0x13, 0xa0, 0xdd, 0x5b, 0xe3, 0xbd, 0xf3, 0xb9, 0xb1, 0xe0, - 0xc5, 0xf2, 0xfc, 0x66, 0xf6, 0x37, 0x7f, 0x76, 0x66, 0x6e, 0xa1, 0x99, 0xf0, 0x08, 0xa7, 0x67, - 0x32, 0x0d, 0x98, 0x08, 0x42, 0x19, 0x73, 0xd6, 0x99, 0xa5, 0x5c, 0x72, 0x52, 0xd5, 0x0a, 0xef, - 0xf7, 0x87, 0x50, 0x1b, 0xae, 0x94, 0x84, 0xc2, 0x83, 0xef, 0x31, 0x15, 0x31, 0x67, 0xd4, 0x69, - 0x39, 0xed, 0x03, 0x7f, 0x29, 0x92, 0x43, 0xa8, 0x5c, 0x5d, 0xd0, 0x4a, 0xcb, 0x69, 0xbb, 0x7e, - 0xe5, 0xea, 0x42, 0x59, 0xf6, 0xa6, 0x3c, 0x7c, 0x7b, 0x75, 0x41, 0x5d, 0x0d, 0x2e, 0x45, 0x72, - 0x02, 0x7b, 0x7d, 0x8c, 0xc7, 0x13, 0x49, 0x77, 0x35, 0x85, 0x91, 0xc8, 0x0b, 0x38, 0xbe, 0x45, - 0x16, 0x61, 0x7a, 0x1e, 0x86, 0x7c, 0xce, 0xe4, 0x70, 0x31, 0x43, 0x5a, 0xd5, 0x26, 0xeb, 0x0a, - 0xd2, 0x85, 0x46, 0x0e, 0x3c, 0x8f, 0xa2, 0x14, 0x85, 0xa0, 0x7b, 0x2d, 0xa7, 0xbd, 0xef, 0x97, - 0xea, 0xd4, 0x19, 0x1f, 0xc3, 0x78, 0x16, 0x23, 0x93, 0xb6, 0x93, 0x07, 0xda, 0x49, 0xa9, 0x8e, - 0x7c, 0x01, 0xcd, 0x22, 0xbe, 0x74, 0xf5, 0x50, 0xbb, 0xda, 0xa4, 0x26, 0x6d, 0x78, 0x64, 0x95, - 0x4e, 0x3b, 0xda, 0xd7, 0x8e, 0x8a, 0x30, 0x39, 0x02, 0xf7, 0x12, 0x91, 0x82, 0xae, 0x93, 0xfa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, 0xd3, - 0x81, 0x8f, 0x55, 0x59, 0xde, 0xb0, 0x90, 0xb3, 0x51, 0x9c, 0x26, 0x58, 0xc6, 0xf8, 0x9f, 0x0a, - 0xa4, 0xe2, 0x38, 0x4f, 0xd3, 0xf8, 0xe7, 0x60, 0xba, 0x7a, 0x65, 0x64, 0xa9, 0xaf, 0xe1, 0xe4, - 0x23, 0x80, 0x4b, 0xc4, 0x01, 0xa6, 0x2a, 0x2c, 0xf3, 0x96, 0xb3, 0x90, 0xde, 0xf3, 0x1f, 0xda, - 0xe3, 0x58, 0x4e, 0xe6, 0x77, 0x9d, 0x90, 0x27, 0x67, 0xbf, 0x70, 0x7e, 0x17, 0x66, 0xbf, 0x2f, - 0x43, 0x9e, 0xe2, 0x59, 0xc8, 0x93, 0x84, 0xb3, 0x33, 0x1d, 0xd0, 0xdd, 0x9e, 0x7e, 0x5c, 0x7e, - 0xf6, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb1, 0xf6, 0x2f, 0xe8, 0x77, 0x0a, 0x00, 0x00, + // 905 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xdf, 0x6f, 0x1b, 0xc5, + 0x13, 0xcf, 0xf9, 0xe2, 0xb4, 0x19, 0x3b, 0x69, 0xb2, 0x5f, 0x37, 0x5e, 0x7d, 0x29, 0xc4, 0x9c, + 0x68, 0xb1, 0xaa, 0xd6, 0x91, 0x4c, 0x85, 0x78, 0x42, 0x8a, 0x31, 0xc1, 0x11, 0x29, 0x31, 0x1b, + 0x97, 0x07, 0x24, 0x1e, 0x2e, 0x77, 0x63, 0xfb, 0x54, 0xdf, 0xae, 0xb9, 0x5d, 0x53, 0x19, 0x89, + 0x37, 0xfe, 0x13, 0xc4, 0x03, 0xff, 0x1e, 0x4f, 0x3c, 0xa2, 0xdd, 0xbb, 0x90, 0xbb, 0xf3, 0x3a, + 0xb1, 0xe0, 0xc5, 0xf2, 0x7c, 0x66, 0xf6, 0x33, 0x3f, 0x76, 0x66, 0x6e, 0xa1, 0x19, 0x8b, 0x10, + 0x67, 0x27, 0x2a, 0xf1, 0xb9, 0xf4, 0x03, 0x15, 0x09, 0xde, 0x99, 0x27, 0x42, 0x09, 0x52, 0x35, + 0x0a, 0xef, 0x8f, 0x87, 0x50, 0x1b, 0xdd, 0x2a, 0x09, 0x85, 0x07, 0xdf, 0x61, 0x22, 0x23, 0xc1, + 0xa9, 0xd3, 0x72, 0xda, 0x7b, 0xec, 0x46, 0x24, 0xfb, 0x50, 0x39, 0xef, 0xd3, 0x4a, 0xcb, 0x69, + 0xbb, 0xac, 0x72, 0xde, 0xd7, 0x96, 0xbd, 0x99, 0x08, 0xde, 0x9e, 0xf7, 0xa9, 0x6b, 0xc0, 0x1b, + 0x91, 0x1c, 0xc1, 0xce, 0x00, 0xa3, 0xc9, 0x54, 0xd1, 0x6d, 0x43, 0x91, 0x49, 0xe4, 0x73, 0xf8, + 0xff, 0x15, 0xf2, 0x10, 0x93, 0xd3, 0x20, 0x10, 0x0b, 0xae, 0x4e, 0xc3, 0x30, 0x41, 0x29, 0x2f, + 0x90, 0x4f, 0xd4, 0x94, 0x56, 0x8d, 0xed, 0x1d, 0x16, 0xa4, 0x0b, 0x0d, 0x9b, 0x96, 0xee, 0xb4, + 0x9c, 0xf6, 0x2e, 0xb3, 0xea, 0x48, 0x1f, 0xde, 0x67, 0x18, 0x44, 0xf3, 0x08, 0xb9, 0xb2, 0xba, + 0x7d, 0x60, 0xdc, 0xde, 0x6d, 0x44, 0x3e, 0x83, 0xe6, 0x1a, 0x03, 0xfa, 0xd0, 0x38, 0x5f, 0xa7, + 0x26, 0x6d, 0x78, 0x94, 0x2b, 0xef, 0x68, 0x39, 0x47, 0xba, 0x6b, 0x3c, 0x96, 0x61, 0x72, 0x00, + 0xee, 0x19, 0x22, 0x05, 0x53, 0x4b, 0xfd, 0x97, 0x3c, 0x81, 0xdd, 0x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xcb, 0xf2, 0x86, + 0x07, 0x82, 0x8f, 0xa3, 0x24, 0x46, 0x1b, 0xe3, 0xbf, 0x2a, 0x90, 0x8e, 0xe3, 0x34, 0x49, 0xa2, + 0x9f, 0xfc, 0xd9, 0xed, 0xbb, 0x23, 0x4d, 0x7d, 0x05, 0x27, 0x1f, 0x00, 0x9c, 0x21, 0x0e, 0x31, + 0xd1, 0x61, 0x65, 0x2f, 0xc0, 0x1c, 0xd2, 0x7b, 0xfe, 0x7d, 0x7b, 0x12, 0xa9, 0xe9, 0xe2, 0xba, + 0x13, 0x88, 0xf8, 0xe4, 0x67, 0x21, 0xae, 0x83, 0xf4, 0xf7, 0x65, 0x20, 0x12, 0x3c, 0x09, 0x44, + 0x1c, 0x0b, 0x7e, 0x62, 0x02, 0xba, 0xde, 0x31, 0x4f, 0xd2, 0x4f, 0xfe, 0x0e, 0x00, 0x00, 0xff, + 0xff, 0xf0, 0xfa, 0xfd, 0x79, 0xad, 0x0a, 0x00, 0x00, } diff --git a/core/service/blockCoreService.go b/core/service/blockCoreService.go index 9ea773be3..eaf0d8054 100644 --- a/core/service/blockCoreService.go +++ b/core/service/blockCoreService.go @@ -26,10 +26,10 @@ import ( type ( BlockServiceInterface interface { VerifySeed(seed *big.Int, balance *big.Int, previousBlock *model.Block, timestamp int64) bool - NewBlock(version uint32, previousBlockHash []byte, blockSeed []byte, blocksmithID []byte, hash string, + NewBlock(version uint32, previousBlockHash []byte, blockSeed []byte, blocksmithAddress string, hash string, previousBlockHeight uint32, timestamp int64, totalAmount int64, totalFee int64, totalCoinBase int64, transactions []*model.Transaction, payloadHash []byte, payloadLength uint32, secretPhrase string) *model.Block - NewGenesisBlock(version uint32, previousBlockHash []byte, blockSeed []byte, blocksmithID []byte, + NewGenesisBlock(version uint32, previousBlockHash []byte, blockSeed []byte, blocksmithAddress string, hash string, previousBlockHeight uint32, timestamp int64, totalAmount int64, totalFee int64, totalCoinBase int64, transactions []*model.Transaction, payloadHash []byte, payloadLength uint32, smithScale int64, cumulativeDifficulty *big.Int, genesisSignature []byte) *model.Block @@ -37,7 +37,7 @@ type ( previousBlock *model.Block, secretPhrase string, timestamp int64, - blockSmithAccountID []byte, + blockSmithAccountAddress string, ) (*model.Block, error) PushBlock(previousBlock, block *model.Block) error GetLastBlock() (*model.Block, error) @@ -94,9 +94,8 @@ func NewBlockService( func (bs *BlockService) NewBlock( version uint32, previousBlockHash, - blockSeed, - blocksmithID []byte, - hash string, + blockSeed []byte, + blocksmithAddress, hash string, previousBlockHeight uint32, timestamp, totalAmount, @@ -108,18 +107,19 @@ func (bs *BlockService) NewBlock( secretPhrase string, ) *model.Block { block := &model.Block{ - Version: version, - PreviousBlockHash: previousBlockHash, - BlockSeed: blockSeed, - BlocksmithID: blocksmithID, - Height: previousBlockHeight, - Timestamp: timestamp, - TotalAmount: totalAmount, - TotalFee: totalFee, - TotalCoinBase: totalCoinBase, - Transactions: transactions, - PayloadHash: payloadHash, - PayloadLength: payloadLength, + Version: version, + PreviousBlockHash: previousBlockHash, + BlockSeed: blockSeed, + BlocksmithAddressLength: uint32(len(blocksmithAddress)), + BlocksmithAddress: blocksmithAddress, + Height: previousBlockHeight, + Timestamp: timestamp, + TotalAmount: totalAmount, + TotalFee: totalFee, + TotalCoinBase: totalCoinBase, + Transactions: transactions, + PayloadHash: payloadHash, + PayloadLength: payloadLength, } blockUnsignedByte, _ := coreUtil.GetBlockByte(block, false) block.BlockSignature = bs.Signature.SignByNode(blockUnsignedByte, secretPhrase) @@ -129,8 +129,8 @@ func (bs *BlockService) NewBlock( // NewGenesisBlock create new block that is fixed in the value of cumulative difficulty, smith scale, and the block signature func (bs *BlockService) NewGenesisBlock( version uint32, - previousBlockHash, blockSeed, blocksmithID []byte, - hash string, + previousBlockHash, blockSeed []byte, + blocksmithAddress, hash string, previousBlockHeight uint32, timestamp, totalAmount, totalFee, totalCoinBase int64, transactions []*model.Transaction, @@ -141,21 +141,22 @@ func (bs *BlockService) NewGenesisBlock( genesisSignature []byte, ) *model.Block { block := &model.Block{ - Version: version, - PreviousBlockHash: previousBlockHash, - BlockSeed: blockSeed, - BlocksmithID: blocksmithID, - Height: previousBlockHeight, - Timestamp: timestamp, - TotalAmount: totalAmount, - TotalFee: totalFee, - TotalCoinBase: totalCoinBase, - Transactions: transactions, - PayloadLength: payloadLength, - PayloadHash: payloadHash, - SmithScale: smithScale, - CumulativeDifficulty: cumulativeDifficulty.String(), - BlockSignature: genesisSignature, + Version: version, + PreviousBlockHash: previousBlockHash, + BlockSeed: blockSeed, + BlocksmithAddressLength: uint32(len(blocksmithAddress)), + BlocksmithAddress: blocksmithAddress, + Height: previousBlockHeight, + Timestamp: timestamp, + TotalAmount: totalAmount, + TotalFee: totalFee, + TotalCoinBase: totalCoinBase, + Transactions: transactions, + PayloadLength: payloadLength, + PayloadHash: payloadHash, + SmithScale: smithScale, + CumulativeDifficulty: cumulativeDifficulty.String(), + BlockSignature: genesisSignature, } return block } @@ -304,7 +305,8 @@ func (bs *BlockService) GetGenesisBlock() (*model.Block, error) { &lastBlock.SmithScale, &lastBlock.PayloadLength, &lastBlock.PayloadHash, - &lastBlock.BlocksmithID, + &lastBlock.BlocksmithAddressLength, + &lastBlock.BlocksmithAddress, &lastBlock.TotalAmount, &lastBlock.TotalFee, &lastBlock.TotalCoinBase, @@ -338,8 +340,8 @@ func (bs *BlockService) GetBlocks() ([]*model.Block, error) { for rows.Next() { var block model.Block err = rows.Scan(&block.ID, &block.PreviousBlockHash, &block.Height, &block.Timestamp, &block.BlockSeed, &block.BlockSignature, - &block.CumulativeDifficulty, &block.SmithScale, &block.PayloadLength, &block.PayloadHash, &block.BlocksmithID, &block.TotalAmount, - &block.TotalFee, &block.TotalCoinBase, &block.Version) + &block.CumulativeDifficulty, &block.SmithScale, &block.PayloadLength, &block.PayloadHash, &block.BlocksmithAddressLength, + &block.BlocksmithAddress, &block.TotalAmount, &block.TotalFee, &block.TotalCoinBase, &block.Version) if err != nil { return nil, err } @@ -367,7 +369,7 @@ func (bs *BlockService) GenerateBlock( previousBlock *model.Block, secretPhrase string, timestamp int64, - blockSmithAccountID []byte, + blockSmithAccountAddress string, ) (*model.Block, error) { var ( totalAmount, totalFee, totalCoinbase int64 @@ -406,7 +408,7 @@ func (bs *BlockService) GenerateBlock( hash := digest.Sum([]byte{}) digest.Reset() // reset the digest _, _ = digest.Write(previousBlock.GetBlockSeed()) - _, _ = digest.Write(blockSmithAccountID) + _, _ = digest.Write([]byte(blockSmithAccountAddress)) blockSeed := digest.Sum([]byte{}) digest.Reset() // reset the digest previousBlockByte, _ := coreUtil.GetBlockByte(previousBlock, true) @@ -415,7 +417,7 @@ func (bs *BlockService) GenerateBlock( 1, previousBlockHash[:], blockSeed, - blockSmithAccountID, + blockSmithAccountAddress, string(hash), newBlockHeight, timestamp, @@ -456,7 +458,7 @@ func (bs *BlockService) AddGenesis() error { 1, nil, make([]byte, 64), - []byte{}, + "", "", 0, constant.GenesisBlockTimestamp, @@ -498,11 +500,10 @@ func (bs *BlockService) CheckSignatureBlock(block *model.Block) bool { if err != nil { return false } - accountAddress, err := util.GetAddressFromPublicKey(block.GetBlocksmithID()) if err != nil { return false } - return bs.Signature.VerifySignature(blockUnsignedByte, block.GetBlockSignature(), 0, accountAddress) + return bs.Signature.VerifySignature(blockUnsignedByte, block.GetBlockSignature(), block.GetBlocksmithAddress()) } return false } diff --git a/core/service/genesisCoreService.go b/core/service/genesisCoreService.go index 177559b45..89acc98e0 100644 --- a/core/service/genesisCoreService.go +++ b/core/service/genesisCoreService.go @@ -33,16 +33,16 @@ func GetGenesisTransactions(chainType contract.ChainType) []*model.Transaction { for _, fundReceiver := range genesisFundReceiver { for receiver, amount := range fundReceiver { genesisTx := &model.Transaction{ - Version: 1, - TransactionType: util.ConvertBytesToUint32([]byte{1, 0, 0, 0}), - Height: 0, - Timestamp: 1562806389280, - SenderAccountType: 0, - SenderAccountAddress: constant.GenesisAccountAddress, - RecipientAccountType: 0, - RecipientAccountAddress: receiver, - Fee: 0, - TransactionBodyLength: 8, + Version: 1, + TransactionType: util.ConvertBytesToUint32([]byte{1, 0, 0, 0}), + Height: 0, + Timestamp: 1562806389280, + SenderAccountAddressLength: uint32(len(constant.GenesisAccountAddress)), + SenderAccountAddress: constant.GenesisAccountAddress, + RecipientAccountAddressLength: uint32(len(receiver)), + RecipientAccountAddress: receiver, + Fee: 0, + TransactionBodyLength: 8, TransactionBody: &model.Transaction_SendMoneyTransactionBody{ SendMoneyTransactionBody: &model.SendMoneyTransactionBody{ Amount: amount, @@ -73,27 +73,19 @@ func GetGenesisTransactions(chainType contract.ChainType) []*model.Transaction { // AddGenesisAccount create genesis account into `account` and `account_balance` table func AddGenesisAccount(executor query.ExecutorInterface) error { // add genesis account - genesisAccount := model.Account{ - ID: util.CreateAccountIDFromAddress(0, constant.GenesisAccountAddress), - AccountType: 0, - Address: constant.GenesisAccountAddress, - } genesisAccountBalance := model.AccountBalance{ - AccountID: genesisAccount.ID, + AccountAddress: constant.GenesisAccountAddress, BlockHeight: 0, SpendableBalance: 0, Balance: 0, PopRevenue: 0, Latest: true, } - genesisAccountInsertQ, genesisAccountInsertArgs := query.NewAccountQuery().InsertAccount(&genesisAccount) genesisAccountBalanceInsertQ, genesisAccountBalanceInsertArgs := query.NewAccountBalanceQuery().InsertAccountBalance( &genesisAccountBalance) _ = executor.BeginTx() var genesisQueries [][]interface{} genesisQueries = append(genesisQueries, - append( - []interface{}{genesisAccountInsertQ}, genesisAccountInsertArgs...), append( []interface{}{genesisAccountBalanceInsertQ}, genesisAccountBalanceInsertArgs...), ) diff --git a/core/service/mempoolCoreService.go b/core/service/mempoolCoreService.go index f77f16f08..93c464b18 100644 --- a/core/service/mempoolCoreService.go +++ b/core/service/mempoolCoreService.go @@ -185,11 +185,9 @@ func (mps *MempoolService) ReceivedTransactionListener() observer.Listener { return observer.Listener{ OnNotify: func(transactionBytes interface{}, args interface{}) { var ( - err error - receivedTx *model.Transaction - mempoolTx *model.MempoolTransaction - recipientAccountID []byte - senderAccountID []byte + err error + receivedTx *model.Transaction + mempoolTx *model.MempoolTransaction ) receivedTxBytes := transactionBytes.([]byte) @@ -197,23 +195,14 @@ func (mps *MempoolService) ReceivedTransactionListener() observer.Listener { if err != nil { return } - if receivedTx.RecipientAccountAddress == "" { - recipientAccountID = nil - } else { - recipientAccountID = util.CreateAccountIDFromAddress( - receivedTx.RecipientAccountType, - receivedTx.RecipientAccountAddress) - } - senderAccountID = util.CreateAccountIDFromAddress(receivedTx.SenderAccountType, - receivedTx.SenderAccountAddress) mempoolTx = &model.MempoolTransaction{ // TODO: how to determine FeePerByte in mempool? - FeePerByte: 0, - ID: receivedTx.ID, - TransactionBytes: receivedTxBytes, - ArrivalTimestamp: time.Now().Unix(), - SenderAccountID: senderAccountID, - RecipientAccountID: recipientAccountID, + FeePerByte: 0, + ID: receivedTx.ID, + TransactionBytes: receivedTxBytes, + ArrivalTimestamp: time.Now().Unix(), + SenderAccountAddress: receivedTx.SenderAccountAddress, + RecipientAccountAddress: receivedTx.RecipientAccountAddress, } // Validate received transaction diff --git a/core/service/nodeAdminCoreService.go b/core/service/nodeAdminCoreService.go index 2d0140a36..86a28e483 100644 --- a/core/service/nodeAdminCoreService.go +++ b/core/service/nodeAdminCoreService.go @@ -32,7 +32,6 @@ type ( NodeAdminService struct { QueryExecutor query.ExecutorInterface BlockQuery query.BlockQueryInterface - AccountQuery query.AccountQueryInterface Signature crypto.SignatureInterface Helpers NodeAdminServiceHelpersInterface BlockService BlockServiceInterface @@ -42,14 +41,12 @@ type ( func NewNodeAdminService( queryExecutor query.ExecutorInterface, blockQuery query.BlockQueryInterface, - accountQuery query.AccountQueryInterface, signature crypto.SignatureInterface, helpers NodeAdminServiceHelpersInterface, blockService BlockServiceInterface) *NodeAdminService { return &NodeAdminService{ queryExecutor, blockQuery, - accountQuery, signature, helpers, blockService, diff --git a/core/smith/blockchainProcessor.go b/core/smith/blockchainProcessor.go index 53d7f08a4..82b774086 100644 --- a/core/smith/blockchainProcessor.go +++ b/core/smith/blockchainProcessor.go @@ -2,6 +2,7 @@ package smith import ( "errors" + "github.com/zoobc/zoobc-core/common/util" "log" "math" "math/big" @@ -17,13 +18,13 @@ type ( // Blocksmith is wrapper for the account in smithing process Blocksmith struct { - NodePublicKey []byte - AccountID []byte - Balance *big.Int - SmithTime int64 - BlockSeed *big.Int - SecretPhrase string - deadline uint32 + NodePublicKey []byte + AccountAddress string + Balance *big.Int + SmithTime int64 + BlockSeed *big.Int + SecretPhrase string + deadline uint32 } // BlockchainProcessor handle smithing process, can be switch to process different chain by supplying different chain type @@ -52,10 +53,9 @@ func NewBlockchainProcessor( func NewBlocksmith(nodeSecretPhrase string) *Blocksmith { // todo: get node[private + public key] + look up account [public key, ID] blocksmith := &Blocksmith{ - AccountID: []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}, - Balance: big.NewInt(1000000000), - SecretPhrase: nodeSecretPhrase, + AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", + Balance: big.NewInt(1000000000), + SecretPhrase: nodeSecretPhrase, NodePublicKey: []byte{153, 58, 50, 200, 7, 61, 108, 229, 204, 48, 199, 145, 21, 99, 125, 75, 49, 45, 118, 97, 219, 80, 242, 244, 100, 134, 144, 246, 37, 144, 213, 135}, } @@ -65,12 +65,11 @@ func NewBlocksmith(nodeSecretPhrase string) *Blocksmith { // CalculateSmith calculate seed, smithTime, and deadline func (*BlockchainProcessor) CalculateSmith(lastBlock *model.Block, generator *Blocksmith) *Blocksmith { account := model.AccountBalance{ - AccountID: []byte{4, 38, 113, 185, 80, 213, 37, 71, 68, 177, 176, 126, 241, 58, 3, 32, 129, 1, 156, 65, 199, 111, - 241, 130, 176, 116, 63, 35, 232, 241, 210, 172}, + AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", Balance: 1000000000, SpendableBalance: 1000000000, } - if len(account.AccountID) == 0 { + if len(account.AccountAddress) == 0 { generator.Balance = big.NewInt(0) } else { accountEffectiveBalance := account.GetBalance() @@ -81,7 +80,8 @@ func (*BlockchainProcessor) CalculateSmith(lastBlock *model.Block, generator *Bl generator.SmithTime = 0 generator.BlockSeed = big.NewInt(0) } - generator.BlockSeed, _ = coreUtil.GetBlockSeed(generator.AccountID, lastBlock) + generatorPublicKey, _ := util.GetPublicKeyFromAddress(generator.AccountAddress) + generator.BlockSeed, _ = coreUtil.GetBlockSeed(generatorPublicKey, lastBlock) generator.SmithTime = coreUtil.GetSmithTime(generator.Balance, generator.BlockSeed, lastBlock) generator.deadline = uint32(math.Max(0, float64(generator.SmithTime-lastBlock.GetTimestamp()))) return generator @@ -95,7 +95,7 @@ func (bp *BlockchainProcessor) StartSmithing() error { } smithMax := time.Now().Unix() - bp.Chaintype.GetChainSmithingDelayTime() bp.Generator = bp.CalculateSmith(lastBlock, bp.Generator) - if lastBlock.GetID() != bp.LastBlockID || bp.Generator.AccountID != nil { + if lastBlock.GetID() != bp.LastBlockID || bp.Generator.AccountAddress != "" { if bp.Generator.SmithTime > smithMax { log.Printf("skip forge\n") return errors.New("SmithSkip") @@ -119,7 +119,7 @@ func (bp *BlockchainProcessor) StartSmithing() error { previousBlock, bp.Generator.SecretPhrase, timestamp, - bp.Generator.AccountID, + bp.Generator.AccountAddress, ) if err != nil { return err diff --git a/core/util/blockUtil.go b/core/util/blockUtil.go index 85bb91206..950e3e2ea 100644 --- a/core/util/blockUtil.go +++ b/core/util/blockUtil.go @@ -124,7 +124,8 @@ func GetBlockByte(block *model.Block, signed bool) ([]byte, error) { buffer.Write(util.ConvertUint64ToBytes(uint64(block.GetTotalCoinBase()))) buffer.Write(util.ConvertUint64ToBytes(uint64(block.GetPayloadLength()))) buffer.Write(block.PayloadHash) - buffer.Write(block.GetBlocksmithID()) + buffer.Write(util.ConvertUint32ToBytes(block.BlocksmithAddressLength)) + buffer.Write([]byte(block.GetBlocksmithAddress())) buffer.Write(block.GetBlockSeed()) buffer.Write(block.GetPreviousBlockHash()) if signed { From 7c1e265672a9ee507bde598b5672e09421f614d2 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 12:49:35 +0800 Subject: [PATCH 03/27] #134 update block id due to account type removal --- common/chaintype/mainchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/chaintype/mainchain.go b/common/chaintype/mainchain.go index 5b883e01d..7beca8f64 100644 --- a/common/chaintype/mainchain.go +++ b/common/chaintype/mainchain.go @@ -20,5 +20,5 @@ func (*MainChain) GetName() string { // GetGenesisBlockID return the block ID of genesis block in the chain func (*MainChain) GetGenesisBlockID() int64 { - return 4545420970999433273 + return -1360700853772335847 } From fdb0895ae562710ebd9a9ac7ca6039a8ff77543b Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 13:17:15 +0800 Subject: [PATCH 04/27] #134 fix sendmoney cmd tools --- api/client/PostTransaction/client.go | 37 +++++++++++----------- cmd/transaction/transactionGenerator.go | 41 ++++++++++++------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/api/client/PostTransaction/client.go b/api/client/PostTransaction/client.go index f051b4a66..c019c145f 100644 --- a/api/client/PostTransaction/client.go +++ b/api/client/PostTransaction/client.go @@ -28,26 +28,27 @@ func main() { // 66, 6, 146, 16, 61, 104, 106, 112, 122, 96, 233, 224, 208, 119, 245, 148, 60, 9, 131, 211, 110, 68, 167, 115, 243, 251, 90, 64, 234, // 66, 108, 30, 116, 9, // }, - // TransactionBytes: []byte{ - // 1, 0, 1, 53, 119, 58, 93, 0, 0, 0, 0, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, 80, 53, 116, 113, 70, 81, 108, 77, 84, 89, 107, 68, - // 101, 66, 86, 70, 87, 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, 84, 106, 103, 116, 78, 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, 1, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 16, 39, 0, 0, 0, 0, 0, 0, 32, 85, 34, 198, 89, 78, - // 166, 142, 59, 148, 243, 133, 69, 66, 123, 219, 2, 3, 229, 172, 221, 35, 185, 208, 43, 44, 172, 96, 166, 116, 205, 93, 78, 194, 153, - // 95, 243, 145, 108, 96, 42, 6, 186, 128, 59, 117, 83, 196, 26, 9, 15, 157, 215, 108, 180, 35, 195, 100, 7, 142, 47, 96, 108, 10, - // }, - // add node TransactionBytes: []byte{ - 2, 0, 1, 218, 138, 66, 93, 0, 0, 0, 0, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, 80, 53, 116, 113, 70, 81, 108, 77, 84, 89, 107, - 68, 101, 66, 86, 70, 87, 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, 84, 106, 103, 116, 78, 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, 1, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 14, 6, 218, 170, 54, 60, 50, 2, 66, 130, 119, 226, - 235, 126, 203, 5, 12, 152, 194, 170, 146, 43, 63, 224, 101, 127, 241, 62, 152, 187, 255, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, - 80, 53, 116, 113, 70, 81, 108, 77, 84, 89, 107, 68, 101, 66, 86, 70, 87, 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, - 84, 106, 103, 116, 78, 9, 49, 50, 55, 46, 48, 46, 48, 46, 49, 160, 134, 1, 0, 0, 0, 0, 0, 118, 96, 0, 82, 83, 206, 138, 84, 224, 106, - 207, 135, 30, 2, 186, 237, 239, 131, 229, 86, 45, 235, 250, 248, 8, 166, 83, 102, 108, 132, 208, 227, 121, 235, 59, 31, 146, 98, 125, - 173, 86, 83, 138, 34, 164, 165, 200, 3, 149, 209, 190, 117, 102, 152, 173, 38, 151, 0, 212, 64, 253, 97, 123, 12, + 1, 0, 0, 0, 1, 189, 0, 77, 93, 0, 0, 0, 0, 44, 0, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, 80, 53, 116, 113, 70, 81, 108, + 77, 84, 89, 107, 68, 101, 66, 86, 70, 87, 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, 84, 106, 103, 116, + 78, 44, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 16, 39, + 0, 0, 0, 0, 0, 0, 180, 143, 228, 156, 234, 214, 183, 43, 200, 112, 178, 166, 134, 156, 224, 252, 184, 87, 52, 253, 43, 41, 14, 33, + 164, 186, 47, 208, 46, 245, 86, 159, 153, 230, 238, 139, 175, 149, 30, 83, 185, 193, 20, 75, 208, 93, 146, 154, 84, 241, 156, 125, + 95, 254, 211, 62, 46, 67, 42, 88, 91, 241, 79, 0, }, + // add node + //TransactionBytes: []byte{ + // 2, 0, 1, 218, 138, 66, 93, 0, 0, 0, 0, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, 80, 53, 116, 113, 70, 81, 108, 77, 84, 89, 107, + // 68, 101, 66, 86, 70, 87, 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, 84, 106, 103, 116, 78, 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, 1, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 14, 6, 218, 170, 54, 60, 50, 2, 66, 130, 119, 226, + // 235, 126, 203, 5, 12, 152, 194, 170, 146, 43, 63, 224, 101, 127, 241, 62, 152, 187, 255, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, + // 80, 53, 116, 113, 70, 81, 108, 77, 84, 89, 107, 68, 101, 66, 86, 70, 87, 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, + // 84, 106, 103, 116, 78, 9, 49, 50, 55, 46, 48, 46, 48, 46, 49, 160, 134, 1, 0, 0, 0, 0, 0, 118, 96, 0, 82, 83, 206, 138, 84, 224, 106, + // 207, 135, 30, 2, 186, 237, 239, 131, 229, 86, 45, 235, 250, 248, 8, 166, 83, 102, 108, 132, 208, 227, 121, 235, 59, 31, 146, 98, 125, + // 173, 86, 83, 138, 34, 164, 165, 200, 3, 149, 209, 190, 117, 102, 152, 173, 38, 151, 0, 212, 64, 253, 97, 123, 12, + //}, }) if err != nil { diff --git a/cmd/transaction/transactionGenerator.go b/cmd/transaction/transactionGenerator.go index af28ea201..dc5836b39 100644 --- a/cmd/transaction/transactionGenerator.go +++ b/cmd/transaction/transactionGenerator.go @@ -39,7 +39,6 @@ func GenerateTransactionBytes(logger *logrus.Logger, unsignedTxBytes, _ := util.GetTransactionBytes(tx, false) tx.Signature = signature.Sign( unsignedTxBytes, - tx.SenderAccountType, tx.SenderAccountAddress, seed, ) @@ -64,15 +63,15 @@ func getTransaction(txType []byte) *model.Transaction { case util.ConvertBytesToUint32(txTypeMap["sendMoney"]): amount := int64(10000) return &model.Transaction{ - Version: 1, - TransactionType: util.ConvertBytesToUint32(txTypeMap["sendMoney"]), - Timestamp: time.Now().Unix(), - SenderAccountType: 0, - SenderAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", - RecipientAccountType: 0, - RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", - Fee: 1, - TransactionBodyLength: 8, + Version: 1, + TransactionType: util.ConvertBytesToUint32(txTypeMap["sendMoney"]), + Timestamp: time.Now().Unix(), + SenderAccountAddressLength: uint32(len("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN")), + SenderAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", + RecipientAccountAddressLength: uint32(len("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J")), + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1, + TransactionBodyLength: 8, TransactionBody: &model.Transaction_SendMoneyTransactionBody{ SendMoneyTransactionBody: &model.SendMoneyTransactionBody{ Amount: amount, @@ -82,8 +81,8 @@ func getTransaction(txType []byte) *model.Transaction { } case util.ConvertBytesToUint32(txTypeMap["registerNode"]): txBody := &model.NodeRegistrationTransactionBody{ - AccountType: 0, - AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", + AccountAddressLength: uint32(len("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN")), + AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", NodePublicKey: []byte{ 0, 14, 6, 218, 170, 54, 60, 50, 2, 66, 130, 119, 226, 235, 126, 203, 5, 12, 152, 194, 170, 146, 43, 63, 224, 101, 127, 241, 62, 152, 187, 255, @@ -96,15 +95,15 @@ func getTransaction(txType []byte) *model.Transaction { Body: txBody, }).GetBodyBytes() return &model.Transaction{ - Version: 1, - TransactionType: util.ConvertBytesToUint32(txTypeMap["registerNode"]), - Timestamp: time.Now().Unix(), - SenderAccountType: 0, - SenderAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", - RecipientAccountType: 0, - RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", - Fee: 1, - TransactionBodyLength: uint32(len(txBodyBytes)), + Version: 1, + TransactionType: util.ConvertBytesToUint32(txTypeMap["registerNode"]), + Timestamp: time.Now().Unix(), + SenderAccountAddressLength: uint32(len("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN")), + SenderAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", + RecipientAccountAddressLength: uint32(len("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J")), + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1, + TransactionBodyLength: uint32(len(txBodyBytes)), TransactionBody: &model.Transaction_NodeRegistrationTransactionBody{ NodeRegistrationTransactionBody: txBody, }, From 1c4a2ed4aaa6db0924983ce1cc201f27c77d1896 Mon Sep 17 00:00:00 2001 From: astaphobia Date: Fri, 9 Aug 2019 13:46:22 +0800 Subject: [PATCH 05/27] fixed undefined BlockSmithID --- api/service/accountBalanceApiService_test.go | 12 +- api/service/blockApiService_test.go | 8 +- common/model/accountBalance.pb.go | 72 ++++----- common/model/block.pb.go | 117 +++++++------- common/model/mempool.pb.go | 74 ++++----- common/model/nodeRegistration.pb.go | 122 ++++++--------- common/model/transaction.pb.go | 152 +++++++++---------- common/query/blockQuery.go | 27 +++- common/schema | 2 +- 9 files changed, 282 insertions(+), 304 deletions(-) diff --git a/api/service/accountBalanceApiService_test.go b/api/service/accountBalanceApiService_test.go index 34d26bdd1..b8f24a922 100644 --- a/api/service/accountBalanceApiService_test.go +++ b/api/service/accountBalanceApiService_test.go @@ -3,12 +3,13 @@ package service import ( "database/sql" "errors" - "github.com/DATA-DOG/go-sqlmock" - "github.com/zoobc/zoobc-core/common/model" - "github.com/zoobc/zoobc-core/common/query" "reflect" "regexp" "testing" + + "github.com/DATA-DOG/go-sqlmock" + "github.com/zoobc/zoobc-core/common/model" + "github.com/zoobc/zoobc-core/common/query" ) type ( @@ -71,7 +72,6 @@ func TestAccountBalanceService_GetAccountBalance(t *testing.T) { Executor: &mockExecutorGetAccountBalanceFail{}, }, args: args{request: &model.GetAccountBalanceRequest{ - AccountType: 0, AccountAddress: "BCZ000000000000", }}, want: nil, @@ -84,7 +84,6 @@ func TestAccountBalanceService_GetAccountBalance(t *testing.T) { Executor: &mockExecutorGetAccountBalanceNotFound{}, }, args: args{request: &model.GetAccountBalanceRequest{ - AccountType: 0, AccountAddress: "BCZ000000000000", }}, want: nil, @@ -97,12 +96,11 @@ func TestAccountBalanceService_GetAccountBalance(t *testing.T) { Executor: &mockExecutorGetAccountBalanceSuccess{}, }, args: args{request: &model.GetAccountBalanceRequest{ - AccountType: 0, AccountAddress: "BCZ000000000000", }}, want: &model.GetAccountBalanceResponse{ AccountBalance: &model.AccountBalance{ - AccountID: []byte{1}, + AccountAddress: "", BlockHeight: 1, SpendableBalance: 10000, Balance: 10000, diff --git a/api/service/blockApiService_test.go b/api/service/blockApiService_test.go index 5a20c0680..bb7bb4edb 100644 --- a/api/service/blockApiService_test.go +++ b/api/service/blockApiService_test.go @@ -147,7 +147,7 @@ func TestBlockService_GetBlockByID(t *testing.T) { SmithScale: 1, PayloadLength: 2, PayloadHash: []byte{}, - BlocksmithID: []byte{}, + BlocksmithAddress: "", TotalAmount: 0, TotalFee: 0, TotalCoinBase: 0, @@ -232,7 +232,7 @@ func TestBlockService_GetBlockByHeight(t *testing.T) { SmithScale: 1, PayloadLength: 2, PayloadHash: []byte{}, - BlocksmithID: []byte{}, + BlocksmithAddress: "", TotalAmount: 0, TotalFee: 0, TotalCoinBase: 0, @@ -322,7 +322,7 @@ func TestBlockService_GetBlocks(t *testing.T) { SmithScale: 1, PayloadLength: 2, PayloadHash: []byte{}, - BlocksmithID: []byte{}, + BlocksmithAddress: "", TotalAmount: 0, TotalFee: 0, TotalCoinBase: 0, @@ -339,7 +339,7 @@ func TestBlockService_GetBlocks(t *testing.T) { SmithScale: 1, PayloadLength: 2, PayloadHash: []byte{}, - BlocksmithID: []byte{}, + BlocksmithAddress: "", TotalAmount: 0, TotalFee: 0, TotalCoinBase: 0, diff --git a/common/model/accountBalance.pb.go b/common/model/accountBalance.pb.go index 7cc3ad630..bb6f434f8 100644 --- a/common/model/accountBalance.pb.go +++ b/common/model/accountBalance.pb.go @@ -22,7 +22,7 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // AccountBalance represent the transaction data structure stored in the database type AccountBalance struct { - AccountID []byte `protobuf:"bytes,1,opt,name=AccountID,proto3" json:"AccountID,omitempty"` + AccountAddress string `protobuf:"bytes,1,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` BlockHeight uint32 `protobuf:"varint,2,opt,name=BlockHeight,proto3" json:"BlockHeight,omitempty"` SpendableBalance int64 `protobuf:"varint,3,opt,name=SpendableBalance,proto3" json:"SpendableBalance,omitempty"` Balance int64 `protobuf:"varint,4,opt,name=Balance,proto3" json:"Balance,omitempty"` @@ -58,11 +58,11 @@ func (m *AccountBalance) XXX_DiscardUnknown() { var xxx_messageInfo_AccountBalance proto.InternalMessageInfo -func (m *AccountBalance) GetAccountID() []byte { +func (m *AccountBalance) GetAccountAddress() string { if m != nil { - return m.AccountID + return m.AccountAddress } - return nil + return "" } func (m *AccountBalance) GetBlockHeight() uint32 { @@ -102,8 +102,7 @@ func (m *AccountBalance) GetLatest() bool { type GetAccountBalanceRequest struct { // Fetch AccountBalance by type/address - AccountType uint32 `protobuf:"varint,1,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,2,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + AccountAddress string `protobuf:"bytes,1,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -134,13 +133,6 @@ func (m *GetAccountBalanceRequest) XXX_DiscardUnknown() { var xxx_messageInfo_GetAccountBalanceRequest proto.InternalMessageInfo -func (m *GetAccountBalanceRequest) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *GetAccountBalanceRequest) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -341,32 +333,30 @@ func init() { func init() { proto.RegisterFile("model/accountBalance.proto", fileDescriptor_44b9b1c521a5bcaa) } var fileDescriptor_44b9b1c521a5bcaa = []byte{ - // 417 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xd1, 0xae, 0x93, 0x40, - 0x10, 0x86, 0xc3, 0xe1, 0x94, 0xe3, 0x99, 0x63, 0x4d, 0xdd, 0x44, 0x43, 0xab, 0x31, 0x84, 0x0b, - 0x43, 0x1a, 0x85, 0x44, 0x6f, 0xd5, 0xd8, 0xc6, 0xc4, 0x9a, 0xf4, 0xc2, 0x6c, 0x7b, 0xd5, 0x3b, - 0x58, 0x26, 0x85, 0x08, 0x2c, 0xc2, 0xa2, 0xb1, 0xaf, 0xe0, 0x03, 0xf8, 0x56, 0x3e, 0x93, 0xe9, - 0x76, 0xb1, 0x14, 0x68, 0x73, 0x6e, 0x48, 0xf6, 0xfb, 0xff, 0x99, 0xd9, 0xd9, 0x19, 0x60, 0x92, - 0xf2, 0x10, 0x13, 0xcf, 0x67, 0x8c, 0x57, 0x99, 0x98, 0xfb, 0x89, 0x9f, 0x31, 0x74, 0xf3, 0x82, - 0x0b, 0x4e, 0x06, 0x52, 0xb3, 0xff, 0x6a, 0xf0, 0x68, 0x76, 0xa2, 0x93, 0xe7, 0x70, 0xab, 0xc8, - 0x97, 0x4f, 0xa6, 0x66, 0x69, 0xce, 0x43, 0x7a, 0x04, 0xc4, 0x82, 0xbb, 0x79, 0xc2, 0xd9, 0xb7, - 0x05, 0xc6, 0xdb, 0x48, 0x98, 0x57, 0x96, 0xe6, 0x0c, 0x69, 0x13, 0x91, 0x29, 0x8c, 0x56, 0x39, - 0x66, 0xa1, 0x1f, 0x24, 0xa8, 0x72, 0x9a, 0xba, 0xa5, 0x39, 0x3a, 0xed, 0x70, 0x62, 0xc2, 0x4d, - 0x6d, 0xb9, 0x96, 0x96, 0xfa, 0x48, 0x5e, 0x00, 0x7c, 0xe5, 0x39, 0xc5, 0x1f, 0x98, 0x55, 0x68, - 0x0e, 0xa4, 0xd8, 0x20, 0xe4, 0x29, 0x18, 0x4b, 0x5f, 0x60, 0x29, 0x4c, 0xc3, 0xd2, 0x9c, 0x07, - 0x54, 0x9d, 0xec, 0x10, 0xcc, 0xcf, 0x28, 0x4e, 0x5b, 0xa2, 0xf8, 0xbd, 0xc2, 0x52, 0xec, 0xef, - 0xae, 0x84, 0xf5, 0xaf, 0x1c, 0x65, 0x6f, 0x43, 0xda, 0x44, 0xe4, 0xe5, 0xff, 0xd7, 0x98, 0x85, - 0x61, 0x81, 0x65, 0x29, 0x1b, 0xbc, 0xa5, 0x2d, 0x6a, 0x6f, 0x60, 0xdc, 0x53, 0xa5, 0xcc, 0x79, - 0x56, 0x22, 0x79, 0xdf, 0x7e, 0x52, 0x59, 0xe9, 0xee, 0xcd, 0x13, 0x57, 0xbe, 0xb9, 0xdb, 0x0a, - 0x6b, 0x99, 0xed, 0x3f, 0x7a, 0x4f, 0xf2, 0xb2, 0xee, 0x61, 0x0a, 0x23, 0x85, 0x96, 0xfc, 0x27, - 0x16, 0xeb, 0xc8, 0xcf, 0x54, 0x23, 0x1d, 0x4e, 0x5e, 0xc1, 0x63, 0xc5, 0x16, 0xf1, 0x36, 0x52, - 0xe6, 0xc3, 0xc4, 0xba, 0x02, 0x79, 0x07, 0xe3, 0xf6, 0x7c, 0x8e, 0x25, 0x74, 0x19, 0x75, 0xde, - 0x40, 0x3e, 0xc0, 0xa4, 0x2d, 0x36, 0x8a, 0x5e, 0xcb, 0xf0, 0x0b, 0x8e, 0x7d, 0xfc, 0x71, 0xba, - 0x9d, 0xf2, 0x83, 0x43, 0xfc, 0x79, 0x07, 0xf9, 0x08, 0xcf, 0x3a, 0x6a, 0xe3, 0x02, 0x86, 0x4c, - 0x70, 0xc9, 0xd2, 0xde, 0xec, 0x9b, 0xce, 0x66, 0xdb, 0xbf, 0x35, 0x98, 0xf4, 0x4d, 0x46, 0xcd, - 0xdd, 0x05, 0x72, 0x2a, 0xad, 0xe2, 0x5d, 0xbd, 0x65, 0x3d, 0x4a, 0xcf, 0x9e, 0x5c, 0x59, 0xfa, - 0xbd, 0xf7, 0x64, 0x3e, 0xdd, 0x38, 0xdb, 0x58, 0x44, 0x55, 0xe0, 0x32, 0x9e, 0x7a, 0x3b, 0xce, - 0x03, 0x76, 0xf8, 0xbe, 0x66, 0xbc, 0x40, 0x8f, 0xf1, 0x34, 0xe5, 0x99, 0x27, 0x53, 0x05, 0x86, - 0xfc, 0xe9, 0xdf, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x49, 0x83, 0x70, 0x94, 0x12, 0x04, 0x00, - 0x00, + // 395 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xc1, 0x6e, 0x9b, 0x40, + 0x10, 0x15, 0xc6, 0xc6, 0xed, 0x58, 0xae, 0xdc, 0x95, 0x5a, 0x61, 0x57, 0xaa, 0x10, 0x87, 0x0a, + 0x59, 0x2d, 0x48, 0xcd, 0x35, 0x89, 0x62, 0x2e, 0xf1, 0xc1, 0x87, 0x08, 0xe7, 0xe4, 0x1b, 0x2c, + 0x23, 0x83, 0x02, 0x2c, 0x81, 0x25, 0x91, 0xfc, 0x0b,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0x7c, 0x77, 0xc3, 0x29, 0x8c, 0x4a, 0x68, 0xc1, 0x9e, 0x31, 0xbb, 0x0f, 0xdc, 0x44, 0xd8, 0x0f, + 0x9d, 0x06, 0x4e, 0xfe, 0xc2, 0xf7, 0x12, 0x9b, 0x87, 0xeb, 0xa0, 0x14, 0x6f, 0xf3, 0x68, 0x12, + 0xe4, 0x12, 0xc6, 0xf5, 0xe9, 0xef, 0x5b, 0xc8, 0xa2, 0xea, 0xb8, 0x80, 0x5c, 0xc3, 0xa4, 0x4e, + 0x56, 0x9a, 0x76, 0x45, 0xf9, 0x09, 0xc5, 0x47, 0xfd, 0x3e, 0xbb, 0x46, 0xfb, 0xde, 0xb6, 0xfe, + 0xb8, 0x82, 0xdc, 0xc0, 0xaf, 0x06, 0x5b, 0xb9, 0x80, 0x22, 0x0c, 0x4e, 0x49, 0xea, 0x7b, 0xdb, + 0x6f, 0xec, 0xad, 0xfe, 0x22, 0xc1, 0xa4, 0x2d, 0x99, 0x32, 0x77, 0x13, 0xc8, 0x21, 0xb5, 0x0c, + 0x37, 0x58, 0x86, 0xd3, 0xc2, 0xb4, 0xec, 0x49, 0x47, 0x93, 0xcf, 0xde, 0x13, 0x7b, 0xba, 0x32, + 0xd6, 0x21, 0x0f, 0x0a, 0xcf, 0xa4, 0x2c, 0xb6, 0x36, 0x8c, 0x79, 0x74, 0xfb, 0xfd, 0x47, 0x59, + 0x86, 0x16, 0x65, 0x71, 0xcc, 0x12, 0x4b, 0x58, 0x79, 0x8a, 0xf8, 0xb9, 0x2f, 0xde, 0x03, 0x00, + 0x00, 0xff, 0xff, 0x14, 0x15, 0x28, 0xbf, 0xfa, 0x03, 0x00, 0x00, } diff --git a/common/model/block.pb.go b/common/model/block.pb.go index 05ff7fff6..f45278c57 100644 --- a/common/model/block.pb.go +++ b/common/model/block.pb.go @@ -22,25 +22,26 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Block represent the block data structure stored in the database type Block struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - PreviousBlockHash []byte `protobuf:"bytes,2,opt,name=PreviousBlockHash,proto3" json:"PreviousBlockHash,omitempty"` - Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` - Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` - BlockSeed []byte `protobuf:"bytes,5,opt,name=BlockSeed,proto3" json:"BlockSeed,omitempty"` - BlockSignature []byte `protobuf:"bytes,6,opt,name=BlockSignature,proto3" json:"BlockSignature,omitempty"` - CumulativeDifficulty string `protobuf:"bytes,7,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` - SmithScale int64 `protobuf:"varint,8,opt,name=SmithScale,proto3" json:"SmithScale,omitempty"` - BlocksmithID []byte `protobuf:"bytes,9,opt,name=BlocksmithID,proto3" json:"BlocksmithID,omitempty"` - TotalAmount int64 `protobuf:"varint,10,opt,name=TotalAmount,proto3" json:"TotalAmount,omitempty"` - TotalFee int64 `protobuf:"varint,11,opt,name=TotalFee,proto3" json:"TotalFee,omitempty"` - TotalCoinBase int64 `protobuf:"varint,12,opt,name=TotalCoinBase,proto3" json:"TotalCoinBase,omitempty"` - Version uint32 `protobuf:"varint,13,opt,name=Version,proto3" json:"Version,omitempty"` - PayloadLength uint32 `protobuf:"varint,14,opt,name=PayloadLength,proto3" json:"PayloadLength,omitempty"` - PayloadHash []byte `protobuf:"bytes,15,opt,name=PayloadHash,proto3" json:"PayloadHash,omitempty"` - Transactions []*Transaction `protobuf:"bytes,16,rep,name=Transactions,proto3" json:"Transactions,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` + PreviousBlockHash []byte `protobuf:"bytes,2,opt,name=PreviousBlockHash,proto3" json:"PreviousBlockHash,omitempty"` + Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` + Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` + BlockSeed []byte `protobuf:"bytes,5,opt,name=BlockSeed,proto3" json:"BlockSeed,omitempty"` + BlockSignature []byte `protobuf:"bytes,6,opt,name=BlockSignature,proto3" json:"BlockSignature,omitempty"` + CumulativeDifficulty string `protobuf:"bytes,7,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` + SmithScale int64 `protobuf:"varint,8,opt,name=SmithScale,proto3" json:"SmithScale,omitempty"` + BlocksmithAddressLength uint32 `protobuf:"varint,9,opt,name=BlocksmithAddressLength,proto3" json:"BlocksmithAddressLength,omitempty"` + BlocksmithAddress string `protobuf:"bytes,10,opt,name=BlocksmithAddress,proto3" json:"BlocksmithAddress,omitempty"` + TotalAmount int64 `protobuf:"varint,11,opt,name=TotalAmount,proto3" json:"TotalAmount,omitempty"` + TotalFee int64 `protobuf:"varint,12,opt,name=TotalFee,proto3" json:"TotalFee,omitempty"` + TotalCoinBase int64 `protobuf:"varint,13,opt,name=TotalCoinBase,proto3" json:"TotalCoinBase,omitempty"` + Version uint32 `protobuf:"varint,14,opt,name=Version,proto3" json:"Version,omitempty"` + PayloadLength uint32 `protobuf:"varint,15,opt,name=PayloadLength,proto3" json:"PayloadLength,omitempty"` + PayloadHash []byte `protobuf:"bytes,16,opt,name=PayloadHash,proto3" json:"PayloadHash,omitempty"` + Transactions []*Transaction `protobuf:"bytes,17,rep,name=Transactions,proto3" json:"Transactions,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Block) Reset() { *m = Block{} } @@ -124,11 +125,18 @@ func (m *Block) GetSmithScale() int64 { return 0 } -func (m *Block) GetBlocksmithID() []byte { +func (m *Block) GetBlocksmithAddressLength() uint32 { if m != nil { - return m.BlocksmithID + return m.BlocksmithAddressLength } - return nil + return 0 +} + +func (m *Block) GetBlocksmithAddress() string { + if m != nil { + return m.BlocksmithAddress + } + return "" } func (m *Block) GetTotalAmount() int64 { @@ -375,36 +383,37 @@ func init() { func init() { proto.RegisterFile("model/block.proto", fileDescriptor_baa78346dbb08dbe) } var fileDescriptor_baa78346dbb08dbe = []byte{ - // 493 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x5d, 0x6b, 0x13, 0x41, - 0x14, 0x65, 0xd3, 0x24, 0x6d, 0x6e, 0x3e, 0xda, 0x0c, 0x45, 0x87, 0x22, 0xb2, 0x84, 0x22, 0x8b, - 0x68, 0x02, 0x15, 0x7c, 0x37, 0x09, 0xda, 0x40, 0x1f, 0xca, 0x26, 0x28, 0xf8, 0x20, 0x4c, 0x36, - 0xb7, 0xd9, 0xc1, 0x9d, 0x99, 0xb8, 0x33, 0x5b, 0x88, 0xef, 0xfe, 0x26, 0xff, 0x9e, 0xec, 0xdd, - 0x6d, 0xb3, 0x51, 0x83, 0xbe, 0x84, 0x9c, 0x73, 0xee, 0x9c, 0x3b, 0x7b, 0xef, 0x19, 0xe8, 0x2b, - 0xb3, 0xc2, 0x64, 0xb4, 0x4c, 0x4c, 0xf4, 0x75, 0xb8, 0x49, 0x8d, 0x33, 0xac, 0x41, 0xd4, 0xc5, - 0xd3, 0x42, 0x71, 0xa9, 0xd0, 0x56, 0x44, 0x4e, 0x1a, 0x5d, 0xe8, 0x83, 0x9f, 0x75, 0x68, 0x8c, - 0xf3, 0x7a, 0xd6, 0x83, 0xda, 0x6c, 0xca, 0x3d, 0xdf, 0x0b, 0x8e, 0xc2, 0xda, 0x6c, 0xca, 0x5e, - 0x41, 0xff, 0x36, 0xc5, 0x7b, 0x69, 0x32, 0x4b, 0x05, 0xd7, 0xc2, 0xc6, 0xbc, 0xe6, 0x7b, 0x41, - 0x27, 0xfc, 0x53, 0x60, 0x4f, 0xa0, 0x79, 0x8d, 0x72, 0x1d, 0x3b, 0x7e, 0xe4, 0x7b, 0x41, 0x37, - 0x2c, 0x11, 0x7b, 0x06, 0xad, 0x85, 0x54, 0x68, 0x9d, 0x50, 0x1b, 0x5e, 0x27, 0xf3, 0x1d, 0x91, - 0xab, 0x64, 0x31, 0x47, 0x5c, 0xf1, 0x06, 0x79, 0xef, 0x08, 0xf6, 0x02, 0x7a, 0x05, 0x90, 0x6b, - 0x2d, 0x5c, 0x96, 0x22, 0x6f, 0x52, 0xc9, 0x6f, 0x2c, 0xbb, 0x82, 0xf3, 0x49, 0xa6, 0xb2, 0x44, - 0x38, 0x79, 0x8f, 0x53, 0x79, 0x77, 0x27, 0xa3, 0x2c, 0x71, 0x5b, 0x7e, 0xec, 0x7b, 0x41, 0x2b, - 0xfc, 0xab, 0xc6, 0x9e, 0x03, 0xcc, 0x95, 0x74, 0xf1, 0x3c, 0x12, 0x09, 0xf2, 0x13, 0xba, 0x58, - 0x85, 0x61, 0x03, 0xe8, 0x50, 0x17, 0x9b, 0x53, 0xb3, 0x29, 0x6f, 0x51, 0xe7, 0x3d, 0x8e, 0xf9, - 0xd0, 0x5e, 0x18, 0x27, 0x92, 0x77, 0xca, 0x64, 0xda, 0x71, 0x20, 0x93, 0x2a, 0xc5, 0x2e, 0xe0, - 0x84, 0xe0, 0x7b, 0x44, 0xde, 0x26, 0xf9, 0x11, 0xb3, 0x4b, 0xe8, 0xd2, 0xff, 0x89, 0x91, 0x7a, - 0x2c, 0x2c, 0xf2, 0x0e, 0x15, 0xec, 0x93, 0x8c, 0xc3, 0xf1, 0x47, 0x4c, 0xad, 0x34, 0x9a, 0x77, - 0x69, 0xb0, 0x0f, 0x30, 0x3f, 0x7f, 0x2b, 0xb6, 0x89, 0x11, 0xab, 0x1b, 0xd4, 0x6b, 0x17, 0xf3, - 0x1e, 0xe9, 0xfb, 0x64, 0x7e, 0xc7, 0x92, 0xa0, 0xfd, 0x9d, 0xd2, 0x67, 0x54, 0x29, 0xf6, 0x16, - 0x3a, 0x8b, 0x5d, 0x2c, 0x2c, 0x3f, 0xf3, 0x8f, 0x82, 0xf6, 0x15, 0x1b, 0x52, 0x62, 0x86, 0x15, - 0x29, 0xdc, 0xab, 0x1b, 0x7c, 0x82, 0xd3, 0x0f, 0xe8, 0x68, 0x20, 0x21, 0x7e, 0xcb, 0xd0, 0xd2, - 0xb2, 0x27, 0xb1, 0x90, 0x7a, 0xb1, 0xdd, 0x20, 0x25, 0xa9, 0x11, 0xee, 0x88, 0x32, 0x60, 0xb5, - 0xc7, 0x80, 0x1d, 0x88, 0xcc, 0xe0, 0x0b, 0x9c, 0x3d, 0x18, 0xdb, 0xff, 0x73, 0x3e, 0x87, 0xc6, - 0x8d, 0x54, 0xd2, 0x91, 0x79, 0x37, 0x2c, 0xc0, 0x41, 0xff, 0x1f, 0x1e, 0xf4, 0x2b, 0x0d, 0xec, - 0xc6, 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa1, 0x25, 0x97, 0x1d, 0x08, 0x1c, 0x0c, 0xfd, 0x25, 0x34, - 0xe9, 0x0d, 0x5a, 0x5e, 0xa7, 0x61, 0x76, 0xca, 0x61, 0x16, 0xc3, 0x2a, 0xb5, 0xf1, 0xcb, 0xcf, - 0xc1, 0x5a, 0xba, 0x38, 0x5b, 0x0e, 0x23, 0xa3, 0x46, 0xdf, 0x8d, 0x59, 0x46, 0xc5, 0xef, 0xeb, - 0xc8, 0xa4, 0x38, 0x8a, 0x8c, 0x52, 0x46, 0x8f, 0xe8, 0xe4, 0xb2, 0x49, 0xaf, 0xf5, 0xcd, 0xaf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0xb2, 0xdb, 0x20, 0xe2, 0x03, 0x00, 0x00, + // 508 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xdf, 0x6b, 0x1a, 0x41, + 0x10, 0xe6, 0x8c,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0x96, 0x5d, 0xc2, 0xe9, 0x28, 0x53, 0x59, 0x22, + 0x9c, 0x7c, 0xc0, 0xb1, 0xbc, 0xbf, 0x97, 0x51, 0x96, 0xb8, 0x15, 0x3f, 0xf4, 0xbd, 0xa0, 0x11, + 0xfe, 0x55, 0x63, 0x2f, 0x00, 0x26, 0x4a, 0xba, 0x78, 0x12, 0x89, 0x04, 0xf9, 0x11, 0x0d, 0xb6, + 0xc1, 0xb0, 0xf7, 0x70, 0x46, 0x5d, 0x6c, 0x4e, 0x5d, 0xcd, 0xe7, 0x29, 0x5a, 0x7b, 0x8b, 0x7a, + 0xe1, 0x62, 0xde, 0xa0, 0x03, 0xee, 0x93, 0xf3, 0xbd, 0xed, 0x48, 0x1c, 0x68, 0x94, 0x5d, 0x81, + 0xf9, 0xd0, 0x9c, 0x1a, 0x27, 0x92, 0x2b, 0x65, 0x32, 0xed, 0x78, 0x93, 0x06, 0xd9, 0xa4, 0xd8, + 0x39, 0x1c, 0x11, 0xfc, 0x80, 0xc8, 0x5b, 0x24, 0x3f, 0x61, 0x76, 0x01, 0x6d, 0xfa, 0x3f, 0x32, + 0x52, 0x0f, 0x85, 0x45, 0xde, 0xa6, 0x82, 0x6d, 0x92, 0x71, 0x38, 0xfc, 0x84, 0xa9, 0x95, 0x46, + 0xf3, 0x0e, 0xcd, 0xfe, 0x08, 0xf3, 0xef, 0xef, 0xc4, 0x2a, 0x31, 0x62, 0x5e, 0x9e, 0xed, 0x98, + 0xf4, 0x6d, 0x32, 0x9f, 0xb1, 0x24, 0x28, 0x03, 0x27, 0x74, 0x09, 0x9b, 0x14, 0x7b, 0x07, 0xad, + 0xe9, 0x3a, 0x5a, 0x96, 0x77, 0xfd, 0x83, 0xa0, 0x79, 0xc9, 0xfa, 0x94, 0xba, 0xfe, 0x86, 0x14, + 0x6e, 0xd5, 0xf5, 0x3e, 0xc3, 0xf1, 0x47, 0x74, 0xb4, 0x95, 0x10, 0xbf, 0x67, 0x68, 0x29, 0x30, + 0xa3, 0x58, 0x48, 0x3d, 0x5d, 0x2d, 0x91, 0xd2, 0x58, 0x0b, 0xd7, 0x44, 0x19, 0xd2, 0xca, 0x53, + 0x48, 0xf7, 0xc4, 0xae, 0xf7, 0x15, 0x4e, 0x1e, 0x8d, 0xed, 0xff, 0x39, 0x9f, 0x42, 0xed, 0x56, + 0x2a, 0xe9, 0xc8, 0xbc, 0x1d, 0x16, 0x60, 0xaf, 0xff, 0x4f, 0x0f, 0xba, 0x1b, 0x0d, 0xec, 0xd2, + 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa2, 0x4b, 0x2e, 0x3b, 0x10, 0xd8, 0xfb, 0x70, 0x2e, 0xa0, 0x4e, + 0xef, 0xd8, 0xf2, 0x2a, 0x2d, 0xb3, 0x55, 0x2e, 0xb3, 0x58, 0x56, 0xa9, 0x0d, 0x5f, 0x7d, 0x09, + 0x16, 0xd2, 0xc5, 0xd9, 0xac, 0x1f, 0x19, 0x35, 0xf8, 0x61, 0xcc, 0x2c, 0x2a, 0x7e, 0xdf, 0x44, + 0x26, 0xc5, 0x41, 0x64, 0x94, 0x32, 0x7a, 0x40, 0x5f, 0xce, 0xea, 0xf4, 0xe2, 0xdf, 0xfe, 0x0e, + 0x00, 0x00, 0xff, 0xff, 0x7c, 0x21, 0x8e, 0x1d, 0x26, 0x04, 0x00, 0x00, } diff --git a/common/model/mempool.pb.go b/common/model/mempool.pb.go index 63aeb3bf7..d185f95ab 100644 --- a/common/model/mempool.pb.go +++ b/common/model/mempool.pb.go @@ -22,15 +22,15 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Mempool represent the mempool data structure stored in the database type MempoolTransaction struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - FeePerByte int32 `protobuf:"varint,2,opt,name=FeePerByte,proto3" json:"FeePerByte,omitempty"` - ArrivalTimestamp int64 `protobuf:"varint,3,opt,name=ArrivalTimestamp,proto3" json:"ArrivalTimestamp,omitempty"` - TransactionBytes []byte `protobuf:"bytes,4,opt,name=TransactionBytes,proto3" json:"TransactionBytes,omitempty"` - SenderAccountID []byte `protobuf:"bytes,5,opt,name=SenderAccountID,proto3" json:"SenderAccountID,omitempty"` - RecipientAccountID []byte `protobuf:"bytes,6,opt,name=RecipientAccountID,proto3" json:"RecipientAccountID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` + FeePerByte int32 `protobuf:"varint,2,opt,name=FeePerByte,proto3" json:"FeePerByte,omitempty"` + ArrivalTimestamp int64 `protobuf:"varint,3,opt,name=ArrivalTimestamp,proto3" json:"ArrivalTimestamp,omitempty"` + TransactionBytes []byte `protobuf:"bytes,4,opt,name=TransactionBytes,proto3" json:"TransactionBytes,omitempty"` + SenderAccountAddress string `protobuf:"bytes,5,opt,name=SenderAccountAddress,proto3" json:"SenderAccountAddress,omitempty"` + RecipientAccountAddress string `protobuf:"bytes,6,opt,name=RecipientAccountAddress,proto3" json:"RecipientAccountAddress,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *MempoolTransaction) Reset() { *m = MempoolTransaction{} } @@ -86,18 +86,18 @@ func (m *MempoolTransaction) GetTransactionBytes() []byte { return nil } -func (m *MempoolTransaction) GetSenderAccountID() []byte { +func (m *MempoolTransaction) GetSenderAccountAddress() string { if m != nil { - return m.SenderAccountID + return m.SenderAccountAddress } - return nil + return "" } -func (m *MempoolTransaction) GetRecipientAccountID() []byte { +func (m *MempoolTransaction) GetRecipientAccountAddress() string { if m != nil { - return m.RecipientAccountID + return m.RecipientAccountAddress } - return nil + return "" } type GetMempoolTransactionRequest struct { @@ -248,26 +248,26 @@ func init() { func init() { proto.RegisterFile("model/mempool.proto", fileDescriptor_22ea31ac6d427b7b) } var fileDescriptor_22ea31ac6d427b7b = []byte{ - // 324 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xcf, 0x4a, 0xc3, 0x40, - 0x10, 0xc6, 0x49, 0xd2, 0xf6, 0x30, 0xf5, 0x1f, 0xdb, 0x4b, 0x04, 0x2d, 0x21, 0xa7, 0x50, 0x30, - 0x01, 0x7d, 0x82, 0xd6, 0x52, 0xa9, 0x22, 0x48, 0x9a, 0x93, 0xb7, 0x74, 0x3b, 0xe8, 0x42, 0x77, - 0x27, 0xee, 0x6e, 0x05, 0xfb, 0x12, 0xbe, 0xad, 0x67, 0xe9, 0xb6, 0x62, 0xb1, 0xeb, 0x25, 0x84, - 0x6f, 0xbe, 0xf9, 0xed, 0xcc, 0xb7, 0x0b, 0x3d, 0x49, 0x0b, 0x5c, 0x16, 0x12, 0x65, 0x43, 0xb4, - 0xcc, 0x1b, 0x4d, 0x96, 0x58, 0xdb, 0x89, 0xe9, 0x57, 0x00, 0xec, 0x71, 0x5b, 0xa8, 0x74, 0xad, - 0x4c, 0xcd, 0xad, 0x20, 0xc5, 0x4e, 0x20, 0x9c, 0x8e, 0xe3, 0x20, 0x09, 0xb2, 0xa8, 0x0c, 0xa7, - 0x63, 0xd6, 0x07, 0x98, 0x20, 0x3e, 0xa1, 0x1e, 0x7d, 0x58, 0x8c, 0xc3, 0x24, 0xc8, 0xda, 0xe5, - 0x9e, 0xc2, 0x06, 0x70, 0x36, 0xd4, 0x5a, 0xbc, 0xd7, 0xcb, 0x4a, 0x48, 0x34, 0xb6, 0x96, 0x4d, - 0x1c, 0xb9, 0xee, 0x03, 0x7d, 0xe3, 0xdd, 0x3b, 0x6a, 0xd3, 0x6e, 0xe2, 0x56, 0x12, 0x64, 0x47, - 0xe5, 0x81, 0xce, 0x32, 0x38, 0x9d, 0xa1, 0x5a, 0xa0, 0x1e, 0x72, 0x4e, 0x2b, 0x65, 0xa7, 0xe3, - 0xb8, 0xed, 0xac, 0x7f, 0x65, 0x96, 0x03, 0x2b, 0x91, 0x8b, 0x46, 0xa0, 0xb2, 0xbf, 0xe6, 0x8e, - 0x33, 0x7b, 0x2a, 0xe9, 0x3d, 0x5c, 0xdc, 0xa1, 0x3d, 0x5c, 0xbd, 0xc4, 0xb7, 0x15, 0x1a, 0xeb, - 0x9d, 0x32, 0xf0, 0x4f, 0x99, 0xde, 0xc2, 0xa5, 0x97, 0x65, 0x7e, 0x60, 0x0c, 0x5a, 0x13, 0x4d, - 0x72, 0x17, 0xa8, 0xfb, 0xdf, 0x44, 0x5c, 0x91, 0x8b, 0x32, 0x2a, 0xc3, 0x8a, 0xd2, 0xcf, 0x00, - 0xfa, 0xff, 0x51, 0x4c, 0x43, 0xca, 0x20, 0x4b, 0xa0, 0xbb, 0x2b, 0xcf, 0xc4, 0x1a, 0x1d, 0xed, - 0xb8, 0xdc, 0x97, 0xd8, 0x03, 0xf4, 0x3c, 0x80, 0x38, 0x4c, 0xa2, 0xac, 0x7b, 0x7d, 0x9e, 0xbb, - 0x3b, 0xcf, 0x3d, 0x4b, 0xfb, 0xba, 0x46, 0x83, 0xe7, 0xec, 0x45, 0xd8, 0xd7, 0xd5, 0x3c, 0xe7, - 0x24, 0x8b, 0x35, 0xd1, 0x9c, 0x6f, 0xbf, 0x57, 0x9c, 0x34, 0x16, 0x9c, 0xa4, 0x24, 0x55, 0x38, - 0xe6, 0xbc, 0xe3, 0x5e, 0xd5, 0xcd, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x97, 0x8a, 0xb5, - 0x6c, 0x02, 0x00, 0x00, + // 332 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x4b, 0xeb, 0x40, + 0x14, 0x85, 0x49, 0xd2, 0x16, 0xde, 0xed, 0x7b, 0x0f, 0x99, 0x0a, 0x46, 0xd0, 0x12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58, 0x07, 0xc7, 0xb7, 0x15, 0x6a, 0xe3, 0x9c, 0xdc, 0x73, 0x4f, 0x1e, 0xdf, 0xc2, + 0xa5, 0x93, 0xa5, 0x7f, 0x60, 0x0c, 0x5a, 0x53, 0x45, 0x72, 0x57, 0xb2, 0xfd, 0xdf, 0xd4, 0x9e, + 0x93, 0xad, 0x37, 0xe0, 0x7e, 0x4e, 0xf1, 0x97, 0x07, 0xfd, 0x63, 0x14, 0xdd, 0x50, 0xad, 0x91, + 0x45, 0xd0, 0xdd, 0xd9, 0xf3, 0x6a, 0x8d, 0x96, 0xf6, 0x8f, 0xef, 0x4b, 0xec, 0x01, 0x7a, 0x0e, + 0x40, 0xe8, 0x47, 0x41, 0xd2, 0x1d, 0x9e, 0xa7, 0x76, 0x0f, 0x52, 0xc7, 0xa3, 0x5d, 0xa9, 0xf1, + 0xe0, 0x39, 0x79, 0xa9, 0xcc, 0xeb, 0x6a, 0x91, 0x0a, 0x92, 0xd9, 0x9a, 0x68, 0x21, 0xb6, 0xdf, + 0x2b, 0x41, 0x0a, 0x33, 0x41, 0x52, 0x52, 0x9d, 0x59, 0xe6, 0xa2, 0x63, 0x37, 0xed, 0xfa, 0x3b, + 0x00, 0x00, 0xff, 0xff, 0xfb, 0x34, 0x78, 0xa7, 0x80, 0x02, 0x00, 0x00, } diff --git a/common/model/nodeRegistration.pb.go b/common/model/nodeRegistration.pb.go index 6615587f4..400be9747 100644 --- a/common/model/nodeRegistration.pb.go +++ b/common/model/nodeRegistration.pb.go @@ -23,7 +23,7 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type NodeRegistration struct { NodeID int64 `protobuf:"varint,1,opt,name=NodeID,proto3" json:"NodeID,omitempty"` NodePublicKey []byte `protobuf:"bytes,2,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountId []byte `protobuf:"bytes,3,opt,name=AccountId,proto3" json:"AccountId,omitempty"` + AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` NodeAddress string `protobuf:"bytes,5,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` LockedBalance int64 `protobuf:"varint,6,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` @@ -74,11 +74,11 @@ func (m *NodeRegistration) GetNodePublicKey() []byte { return nil } -func (m *NodeRegistration) GetAccountId() []byte { +func (m *NodeRegistration) GetAccountAddress() string { if m != nil { - return m.AccountId + return m.AccountAddress } - return nil + return "" } func (m *NodeRegistration) GetRegistrationHeight() uint32 { @@ -126,9 +126,8 @@ func (m *NodeRegistration) GetHeight() uint32 { // GetNodeRegisterRequest create request to get a list node type GetNodeRegistrationsRequest struct { NodePublicKey []byte `protobuf:"bytes,1,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,2,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` - RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` + AccountAddress string `protobuf:"bytes,2,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + RegistrationHeight uint32 `protobuf:"varint,3,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -166,13 +165,6 @@ func (m *GetNodeRegistrationsRequest) GetNodePublicKey() []byte { return nil } -func (m *GetNodeRegistrationsRequest) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *GetNodeRegistrationsRequest) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -190,10 +182,9 @@ func (m *GetNodeRegistrationsRequest) GetRegistrationHeight() uint32 { // GetNodeRegistrationRequest create request for single node register type GetNodeRegistrationRequest struct { NodePublicKey []byte `protobuf:"bytes,1,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,2,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` - RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` - NodeAddress string `protobuf:"bytes,5,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` + AccountAddress string `protobuf:"bytes,2,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + RegistrationHeight uint32 `protobuf:"varint,3,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` + NodeAddress string `protobuf:"bytes,4,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -231,13 +222,6 @@ func (m *GetNodeRegistrationRequest) GetNodePublicKey() []byte { return nil } -func (m *GetNodeRegistrationRequest) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *GetNodeRegistrationRequest) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -263,10 +247,9 @@ func (m *GetNodeRegistrationRequest) GetNodeAddress() string { type UpdateNodeRegistrationRequest struct { ID []byte `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` NodePublicKey []byte `protobuf:"bytes,2,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,3,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,4,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` - NodeAddress string `protobuf:"bytes,5,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` - LockedBalance int64 `protobuf:"varint,6,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` + AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + NodeAddress string `protobuf:"bytes,4,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` + LockedBalance int64 `protobuf:"varint,5,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -311,13 +294,6 @@ func (m *UpdateNodeRegistrationRequest) GetNodePublicKey() []byte { return nil } -func (m *UpdateNodeRegistrationRequest) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *UpdateNodeRegistrationRequest) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -342,14 +318,13 @@ func (m *UpdateNodeRegistrationRequest) GetLockedBalance() int64 { type GetNodeRegistrationsResponse struct { ID []byte `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` NodePublicKey []byte `protobuf:"bytes,2,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,3,opt,name=AccountType,proto3" json:"AccountType,omitempty"` - AccountAddress string `protobuf:"bytes,4,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` - RegistrationHeight uint32 `protobuf:"varint,5,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` - NodeAddress string `protobuf:"bytes,6,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` - LockedBalance int64 `protobuf:"varint,7,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` - Queued bool `protobuf:"varint,8,opt,name=Queued,proto3" json:"Queued,omitempty"` - Latest bool `protobuf:"varint,9,opt,name=Latest,proto3" json:"Latest,omitempty"` - Height uint32 `protobuf:"varint,10,opt,name=Height,proto3" json:"Height,omitempty"` + AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` + RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` + NodeAddress string `protobuf:"bytes,5,opt,name=NodeAddress,proto3" json:"NodeAddress,omitempty"` + LockedBalance int64 `protobuf:"varint,6,opt,name=LockedBalance,proto3" json:"LockedBalance,omitempty"` + Queued bool `protobuf:"varint,7,opt,name=Queued,proto3" json:"Queued,omitempty"` + Latest bool `protobuf:"varint,8,opt,name=Latest,proto3" json:"Latest,omitempty"` + Height uint32 `protobuf:"varint,9,opt,name=Height,proto3" json:"Height,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -394,13 +369,6 @@ func (m *GetNodeRegistrationsResponse) GetNodePublicKey() []byte { return nil } -func (m *GetNodeRegistrationsResponse) GetAccountType() uint32 { - if m != nil { - return m.AccountType - } - return 0 -} - func (m *GetNodeRegistrationsResponse) GetAccountAddress() string { if m != nil { return m.AccountAddress @@ -461,31 +429,29 @@ func init() { func init() { proto.RegisterFile("model/nodeRegistration.proto", fileDescriptor_df1af0ec89e31788) } var fileDescriptor_df1af0ec89e31788 = []byte{ - // 410 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x94, 0xdf, 0xca, 0xd3, 0x30, - 0x18, 0xc6, 0x49, 0xbb, 0x75, 0x6b, 0xf6, 0x07, 0xc9, 0x81, 0x04, 0x9d, 0x50, 0x8a, 0x48, 0x11, - 0x5c, 0x0f, 0xbc, 0x82, 0x0d, 0x41, 0x87, 0x43, 0x34, 0xe8, 0x89, 0x67, 0x6d, 0xf2, 0xb2, 0x15, - 0xd7, 0xa6, 0xb6, 0xe9, 0xc1, 0xbc, 0x28, 0xef, 0xc0, 0x5b, 0xd9, 0xa9, 0xb7, 0x21, 0xc9, 0x2a, - 0x76, 0xb5, 0xd3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0x5f, 0x2b, 0xfd, 0xdc, 0x5f, 0x19, 0xa1, 0xae, - 0x8c, 0x3c, 0x3c, 0xa9, 0x23, 0xf9, 0x78, 0xcc, 0xc1, 0xe4, 0x38, 0x63, 0x4d, 0x44, 0x9e, 0xe1, - 0x79, 0x5d, 0xfe, 0xb6, 0x6e, 0x1b, 0xeb, 0x2d, 0x7a, 0xd3, 0x3c, 0xfd, 0x13, 0xc2, 0x8f, 0x3a, - 0xf4, 0xdf, 0x13, 0xf9, 0xff, 0x6f, 0x07, 0xff, 0x27, 0xc2, 0x4f, 0x3e, 0xe5, 0x22, 0x52, 0x70, - 0xcd, 0xe3, 0x1c, 0x5b, 0x75, 0x6b, 0x4f, 0x99, 0xd5, 0xbb, 0xad, 0x5b, 0x9e, 0xed, 0x3e, 0x9e, - 0x07, 0x9d, 0x9e, 0x6f, 0xa9, 0xa5, 0xfd, 0x93, 0x85, 0x17, 0xdd, 0xad, 0x58, 0xe6, 0x32, 0x2b, - 0xe1, 0xce, 0x8d, 0x76, 0x1f, 0xee, 0xb0, 0xef, 0xe1, 0x3a, 0x3d, 0x82, 0x19, 0xfd, 0x7b, 0xd6, - 0xc7, 0x57, 0x66, 0xdd, 0xbd, 0x32, 0xeb, 0xb8, 0x39, 0xeb, 0xeb, 0xe7, 0x9f, 0x83, 0x5d, 0xa2, - 0xf6, 0x55, 0xbc, 0xe4, 0x32, 0x0d, 0xbf, 0x49, 0x19, 0xf3, 0xf3, 0xef, 0x0b, 0x2e, 0x0b, 0x08, - 0xb9, 0x4c, 0x53, 0x99, 0x85, 0xe6, 0x22, 0x8d, 0x1d, 0x73, 0xad, 0xbe, 0xfc, 0x15, 0x00, 0x00, - 0xff, 0xff, 0xf7, 0xb5, 0x3a, 0x67, 0x76, 0x05, 0x00, 0x00, + // 369 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x94, 0xcf, 0x4a, 0xeb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, 0x60, 0x16, 0x24, 0x02, 0x58, 0x33, 0x97, 0xbf, 0x0e, 0x4d, + 0x77, 0xd7, 0x19, 0x64, 0x20, 0xd9, 0x1f, 0x87, 0x78, 0x2d, 0x5e, 0x54, 0x86, 0x8f, 0x03, 0x0d, + 0x4a, 0xb3, 0xd6, 0x92, 0x2f, 0x2b, 0xc3, 0x0b, 0x6d, 0xed, 0x5c, 0x5b, 0x51, 0xb9, 0x4f, 0x84, + 0xee, 0x9e, 0x82, 0x2e, 0xbb, 0xa7, 0x38, 0xdc, 0x67, 0xe6, 0xbf, 0x0d, 0xb7, 0xc8, 0xc7, 0xdc, + 0xb2, 0x3e, 0xe1, 0x56, 0x6d, 0x9b, 0x5b, 0xee, 0x82, 0xd0, 0x9d, 0x0a, 0x75, 0x3f, 0x42, 0x5c, + 0x79, 0x2b, 0xeb, 0x1b, 0x5b, 0xe9, 0xbe, 0x10, 0xba, 0x77, 0x33, 0x97, 0x81, 0x86, 0x6d, 0x1d, + 0xf4, 0xa8, 0x55, 0x04, 0xb4, 0xc3, 0xad, 0x2f, 0x0f, 0xe7, 0xbb, 0x0a, 0x37, 0xc3, 0xd6, 0xa8, + 0x08, 0x9b, 0xbb, 0xb0, 0x68, 0xbf, 0x3a, 0x24, 0x6a, 0x8e, 0x89, 0x82, 0x6f, 0x6e, 0xe3, 0x97, + 0x9f, 0xb1, 0xd1, 0xe1, 0xad, 0x37, 0x89, 0xf4, 0x34, 0x0b, 0x07, 0x02, 0x63, 0xff, 0x11, 0x31, + 0x14, 0xcb, 0xe7, 0x91, 0xc0, 0x14, 0x7c, 0x81, 0x71, 0x8c, 0x89, 0x9f, 0x5f, 0x65, 0x61, 0x33, + 0xbf, 0xd8, 0x8e, 0x5f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x3b, 0xa0, 0x49, 0x23, 0xf8, 0x04, 0x00, + 0x00, } diff --git a/common/model/transaction.pb.go b/common/model/transaction.pb.go index 92d5280ee..1135c7def 100644 --- a/common/model/transaction.pb.go +++ b/common/model/transaction.pb.go @@ -22,20 +22,20 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Transaction represent the transaction data structure stored in the database type Transaction struct { - 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"` + 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"` + SenderAccountAddressLength uint32 `protobuf:"varint,5,opt,name=SenderAccountAddressLength,proto3" json:"SenderAccountAddressLength,omitempty"` + SenderAccountAddress string `protobuf:"bytes,6,opt,name=SenderAccountAddress,proto3" json:"SenderAccountAddress,omitempty"` + RecipientAccountAddressLength uint32 `protobuf:"varint,7,opt,name=RecipientAccountAddressLength,proto3" json:"RecipientAccountAddressLength,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: @@ -103,9 +103,9 @@ func (m *Transaction) GetHeight() uint32 { return 0 } -func (m *Transaction) GetSenderAccountType() uint32 { +func (m *Transaction) GetSenderAccountAddressLength() uint32 { if m != nil { - return m.SenderAccountType + return m.SenderAccountAddressLength } return 0 } @@ -117,9 +117,9 @@ func (m *Transaction) GetSenderAccountAddress() string { return "" } -func (m *Transaction) GetRecipientAccountType() uint32 { +func (m *Transaction) GetRecipientAccountAddressLength() uint32 { if m != nil { - return m.RecipientAccountType + return m.RecipientAccountAddressLength } return 0 } @@ -325,7 +325,7 @@ func (m *SendMoneyTransactionBody) GetAmount() int64 { type NodeRegistrationTransactionBody struct { NodePublicKey []byte `protobuf:"bytes,1,opt,name=NodePublicKey,proto3" json:"NodePublicKey,omitempty"` - AccountType uint32 `protobuf:"varint,2,opt,name=AccountType,proto3" json:"AccountType,omitempty"` + AccountAddressLength uint32 `protobuf:"varint,2,opt,name=AccountAddressLength,proto3" json:"AccountAddressLength,omitempty"` AccountAddress string `protobuf:"bytes,3,opt,name=AccountAddress,proto3" json:"AccountAddress,omitempty"` RegistrationHeight uint32 `protobuf:"varint,4,opt,name=RegistrationHeight,proto3" json:"RegistrationHeight,omitempty"` NodeAddressLength uint32 `protobuf:"varint,5,opt,name=NodeAddressLength,proto3" json:"NodeAddressLength,omitempty"` @@ -369,9 +369,9 @@ func (m *NodeRegistrationTransactionBody) GetNodePublicKey() []byte { return nil } -func (m *NodeRegistrationTransactionBody) GetAccountType() uint32 { +func (m *NodeRegistrationTransactionBody) GetAccountAddressLength() uint32 { if m != nil { - return m.AccountType + return m.AccountAddressLength } return 0 } @@ -897,59 +897,59 @@ func init() { func init() { proto.RegisterFile("model/transaction.proto", fileDescriptor_8333001f09b34082) } var fileDescriptor_8333001f09b34082 = []byte{ - // 850 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x51, 0x6f, 0xdb, 0x36, - 0x10, 0x8e, 0xac, 0x38, 0x6d, 0xce, 0x4e, 0x9a, 0x70, 0x69, 0x4c, 0x60, 0x05, 0x62, 0x08, 0x6b, - 0x67, 0x14, 0xad, 0x03, 0x78, 0xc5, 0xb0, 0xd7, 0x78, 0xd9, 0xe6, 0x60, 0xe9, 0x92, 0x31, 0xde, - 0x1e, 0x06, 0xec, 0x41, 0x91, 0x2e, 0xb6, 0x50, 0x8b, 0xf4, 0x44, 0x1a, 0x85, 0x07, 0xec, 0x6d, - 0xfb, 0x25, 0xfb, 0x6f, 0xfb, 0x01, 0xfb, 0x05, 0x03, 0x29, 0x7a, 0xa1, 0x64, 0xb9, 0x11, 0xd0, - 0x97, 0x20, 0xf7, 0xdd, 0xf1, 0xfb, 0xee, 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, 0xff, 0xbe, 0x8e, 0x44, 0x86, 0xa7, 0x91, 0x48, 0x53, 0xc1, 0x4f, 0x4d, 0x2a, 0xb7, 0x3b, - 0xe6, 0xc7, 0xdd, 0x17, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x94, 0x02, 0x7e, 0xb0, 0xf7, 0x09, - 0x00, 0x00, + // 859 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x51, 0x6f, 0xe3, 0x44, + 0x10, 0xae, 0xe3, 0xa6, 0x77, 0x9d, 0xa4, 0xbd, 0x76, 0xe9, 0x35, 0x2b, 0x38, 0xd4, 0xc8, 0xe2, + 0x8e, 0xe8, 0x74, 0x97, 0x4a, 0xe1, 0x84, 0x78, 0x42, 0x6a, 0x08, 0x90, 0x8a, 0x1e, 0x2d, 0xdb, + 0xc0, 0x03, 0x12, 0x0f, 0xae, 0x3d, 0x4d, 0xac, 0x8b, 0x77, 0x8d, 0x77, 0xa3, 0x53, 0x90, 0x78, + 0xe3, 0x9f, 0xf0, 0xc4, 0xdf, 0xe3, 0x89, 0x47, 0xb4, 0x6b, 0x97, 0xda, 0xce, 0x26, 0xb5, 0xc4, + 0x4b, 0xd5, 0xf9, 0x66, 0x3c, 0xdf, 0xcc, 0xee, 0x37, 0xb3, 0x81, 0x4e, 0x2c, 0x42, 0x9c, 0x9f, + 0xaa, 0xd4, 0xe7, 0xd2, 0x0f, 0x54, 0x24, 0x78, 0x3f, 0x49, 0x85, 0x12, 0xa4, 0x69, 0x1c, 0xde, + 0x5f, 0x8f, 0xa1, 0x35, 0xb9, 0x77, 0x12, 0x0a, 0x8f, 0x7e, 0xc2, 0x54, 0x46, 0x82, 0x53, 0xa7, + 0xeb, 0xf4, 0xf6, 0xd8, 0x9d, 0x49, 0xf6, 0xa1, 0x71, 0x3e, 0xa2, 0x8d, 0xae, 0xd3, 0x73, 0x59, + 0xe3, 0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 0xc1, 0x47, 0x7d, 0xa3, 0xb9, 0xfe, 0xd7, + 0x96, 0x90, 0xf1, 0x16, 0xb3, 0x7e, 0x4a, 0x7e, 0x01, 0x2a, 0x91, 0x87, 0x6f, 0x05, 0xc7, 0x95, + 0xb4, 0x07, 0x26, 0xed, 0x49, 0x9e, 0xf6, 0x7a, 0x4d, 0xd8, 0x78, 0x8b, 0xad, 0x4d, 0x41, 0x52, + 0x38, 0xe1, 0x22, 0x44, 0x86, 0xd3, 0x48, 0xaa, 0xd4, 0x37, 0xb7, 0x51, 0x61, 0x39, 0x34, 0x2c, + 0x2f, 0x72, 0x96, 0xef, 0x37, 0x47, 0x8f, 0xb7, 0xd8, 0x43, 0x09, 0xc9, 0x1f, 0x0e, 0x3c, 0x5f, + 0x24, 0xa1, 0xaf, 0xf0, 0x81, 0x64, 0x94, 0x18, 0xea, 0x57, 0x39, 0xf5, 0x8f, 0x75, 0xbe, 0x19, + 0x6f, 0xb1, 0x7a, 0xc9, 0xb5, 0xbc, 0xae, 0xa3, 0x29, 0xf7, 0xd5, 0x22, 0x45, 0xfa, 0x81, 0xb9, + 0xd5, 0x7b, 0x60, 0x78, 0x58, 0x92, 0x97, 0xfe, 0xc0, 0x3b, 0x86, 0x23, 0xdb, 0xd5, 0x79, 0x03, + 0xa0, 0xeb, 0xce, 0x5e, 0xef, 0x82, 0xb3, 0x58, 0x0f, 0x84, 0x59, 0x27, 0x2e, 0xcb, 0x2d, 0xef, + 0x9f, 0x06, 0x9c, 0x3c, 0x54, 0xe0, 0x27, 0xb0, 0xa7, 0x43, 0xae, 0x16, 0x37, 0xf3, 0x28, 0xf8, + 0x0e, 0x97, 0x26, 0x45, 0x9b, 0x95, 0x41, 0xad, 0x53, 0xeb, 0x60, 0x37, 0x8c, 0xb8, 0xad, 0x3e, + 0xf2, 0x02, 0xf6, 0x2b, 0x63, 0xec, 0x9a, 0x31, 0xae, 0xa0, 0xa4, 0x0f, 0xa4, 0x58, 0x60, 0x69, + 0xab, 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e5, 0x40, 0x79, 0x17, 0x79, 0x04, 0xcd, 0x8b, 0x28, 0x8e, 0x54, + 0xde, 0x46, 0x66, 0xe8, 0xe1, 0xbe, 0xbc, 0xbd, 0x95, 0xa8, 0x4c, 0xe1, 0xdb, 0x2c, 0xb7, 0xea, + 0x8e, 0x97, 0xf7, 0x3b, 0x74, 0x56, 0xf8, 0x64, 0x22, 0xb8, 0x44, 0x4d, 0x38, 0x11, 0xca, 0x9f, + 0x1b, 0xc2, 0x6d, 0x96, 0x19, 0x1a, 0xfd, 0xca, 0x2c, 0x93, 0x4c, 0x5e, 0x99, 0x41, 0x3e, 0x87, + 0x76, 0x31, 0x07, 0x75, 0xbb, 0x6e, 0xaf, 0x35, 0x20, 0xb9, 0x22, 0x8a, 0x7d, 0x97, 0xe2, 0xbc, + 0x11, 0x1c, 0x5f, 0x09, 0x69, 0x3b, 0x98, 0x97, 0x70, 0x50, 0x9c, 0x85, 0x82, 0x3a, 0x56, 0x70, + 0xef, 0x12, 0x3a, 0x2b, 0x59, 0xf2, 0x26, 0xde, 0x94, 0x7e, 0x5b, 0x99, 0x0c, 0xf6, 0xba, 0x8a, + 0x61, 0xba, 0x2c, 0xbd, 0x4e, 0xff, 0x5f, 0x59, 0xc3, 0x97, 0x3f, 0xf7, 0xa6, 0x91, 0x9a, 0x2d, + 0x6e, 0xfa, 0x81, 0x88, 0x4f, 0x7f, 0x13, 0xe2, 0x26, 0xc8, 0xfe, 0xbe, 0x0e, 0x44, 0x8a, 0xa7, + 0x81, 0x88, 0x63, 0xc1, 0x4f, 0x4d, 0x29, 0x37, 0x3b, 0xe6, 0x27, 0xe1, 0x67, 0xff, 0x06, 0x00, + 0x00, 0xff, 0xff, 0x79, 0xd0, 0x7c, 0x4d, 0x2d, 0x0a, 0x00, 0x00, } diff --git a/common/query/blockQuery.go b/common/query/blockQuery.go index 69ad08ec2..0e54e6451 100644 --- a/common/query/blockQuery.go +++ b/common/query/blockQuery.go @@ -86,24 +86,39 @@ func (*BlockQuery) ExtractModel(block *model.Block) []interface{} { block.BlockSignature, block.CumulativeDifficulty, block.SmithScale, - block.PayloadLength, - block.PayloadHash, block.BlocksmithAddressLength, block.BlocksmithAddress, block.TotalAmount, block.TotalFee, block.TotalCoinBase, block.Version, + block.PayloadLength, + block.PayloadHash, + block.Transactions, } } func (*BlockQuery) BuildModel(blocks []*model.Block, rows *sql.Rows) []*model.Block { for rows.Next() { var block model.Block - _ = rows.Scan(&block.ID, &block.PreviousBlockHash, &block.Height, &block.Timestamp, &block.BlockSeed, - &block.BlockSignature, &block.CumulativeDifficulty, &block.SmithScale, &block.PayloadLength, - &block.PayloadHash, &block.BlocksmithAddressLength, &block.BlocksmithAddress, &block.TotalAmount, &block.TotalFee, - &block.TotalCoinBase, &block.Version) + _ = rows.Scan( + &block.ID, + &block.PreviousBlockHash, + &block.Height, + &block.Timestamp, + &block.BlockSeed, + &block.BlockSignature, + &block.CumulativeDifficulty, + &block.SmithScale, + &block.PayloadLength, + &block.PayloadHash, + &block.BlocksmithAddressLength, + &block.BlocksmithAddress, + &block.TotalAmount, + &block.TotalFee, + &block.TotalCoinBase, + &block.Version, + ) blocks = append(blocks, &block) } return blocks diff --git a/common/schema b/common/schema index d3c0f7dcf..481cc97b1 160000 --- a/common/schema +++ b/common/schema @@ -1 +1 @@ -Subproject commit d3c0f7dcf7dce82b5a466fbaff069a93f6b2c6e0 +Subproject commit 481cc97b1bd01196d208ae9d1b7efa73789d3c42 From e31548ea7dd7888a4617c365b6aa14cbc7042764 Mon Sep 17 00:00:00 2001 From: astaphobia Date: Fri, 9 Aug 2019 13:51:45 +0800 Subject: [PATCH 06/27] fixed GetTransactionsRequest --- api/service/accountBalanceApiService_test.go | 2 +- api/service/transactionApiService_test.go | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/api/service/accountBalanceApiService_test.go b/api/service/accountBalanceApiService_test.go index b8f24a922..f39100c49 100644 --- a/api/service/accountBalanceApiService_test.go +++ b/api/service/accountBalanceApiService_test.go @@ -100,7 +100,7 @@ func TestAccountBalanceService_GetAccountBalance(t *testing.T) { }}, want: &model.GetAccountBalanceResponse{ AccountBalance: &model.AccountBalance{ - AccountAddress: "", + AccountAddress: "\001", BlockHeight: 1, SpendableBalance: 10000, Balance: 10000, diff --git a/api/service/transactionApiService_test.go b/api/service/transactionApiService_test.go index e66108da5..923d065f9 100644 --- a/api/service/transactionApiService_test.go +++ b/api/service/transactionApiService_test.go @@ -508,9 +508,7 @@ func (*mockQueryGetTransactionsSuccess) ExecuteSelect(qStr string, args ...inter 4545420970999433273, 1, 1, - 0, "senderA", - 0, "recipientA", 1, 1, From 87e5f976ff26f746967915b514a456cf9d8e823e Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 14:36:24 +0800 Subject: [PATCH 07/27] #134 fix lint --- api/client/PostTransaction/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/client/PostTransaction/client.go b/api/client/PostTransaction/client.go index c019c145f..d9e20b464 100644 --- a/api/client/PostTransaction/client.go +++ b/api/client/PostTransaction/client.go @@ -38,7 +38,7 @@ func main() { 95, 254, 211, 62, 46, 67, 42, 88, 91, 241, 79, 0, }, // add node - //TransactionBytes: []byte{ + // TransactionBytes: []byte{ // 2, 0, 1, 218, 138, 66, 93, 0, 0, 0, 0, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, 80, 53, 116, 113, 70, 81, 108, 77, 84, 89, 107, // 68, 101, 66, 86, 70, 87, 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, 84, 106, 103, 116, 78, 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, @@ -48,7 +48,7 @@ func main() { // 84, 106, 103, 116, 78, 9, 49, 50, 55, 46, 48, 46, 48, 46, 49, 160, 134, 1, 0, 0, 0, 0, 0, 118, 96, 0, 82, 83, 206, 138, 84, 224, 106, // 207, 135, 30, 2, 186, 237, 239, 131, 229, 86, 45, 235, 250, 248, 8, 166, 83, 102, 108, 132, 208, 227, 121, 235, 59, 31, 146, 98, 125, // 173, 86, 83, 138, 34, 164, 165, 200, 3, 149, 209, 190, 117, 102, 152, 173, 38, 151, 0, 212, 64, 253, 97, 123, 12, - //}, + // }, }) if err != nil { From a804adf4fe82437a2675fb33e9aac2da0dc88bb5 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 14:37:24 +0800 Subject: [PATCH 08/27] #134 fix tests --- common/crypto/signature_test.go | 14 +- core/service/blockCoreService.go | 8 +- core/service/blockCoreService_test.go | 569 +++++++++++------------- core/service/mempoolCoreService_test.go | 174 ++++---- core/smith/blockchainProcessor.go | 2 +- core/util/blockUtil_test.go | 220 ++++----- 6 files changed, 473 insertions(+), 514 deletions(-) diff --git a/common/crypto/signature_test.go b/common/crypto/signature_test.go index e66023e17..4ce466b20 100644 --- a/common/crypto/signature_test.go +++ b/common/crypto/signature_test.go @@ -27,7 +27,6 @@ func TestNewSignature(t *testing.T) { func TestSignature_Sign(t *testing.T) { type args struct { payload []byte - accountType uint32 accountAddress string seed string } @@ -40,7 +39,6 @@ func TestSignature_Sign(t *testing.T) { name: "Sign:valid", args: args{ payload: []byte{12, 43, 65, 65, 12, 123, 43, 12, 1, 24, 5, 5, 12, 54}, - accountType: 0, accountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", seed: "concur vocalist rotten busload gap quote stinging undiluted surfer goofiness deviation starved", }, @@ -52,7 +50,6 @@ func TestSignature_Sign(t *testing.T) { name: "Sign:valid-{default type}", args: args{ payload: []byte{12, 43, 65, 65, 12, 123, 43, 12, 1, 24, 5, 5, 12, 54}, - accountType: 1000, accountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", seed: "concur vocalist rotten busload gap quote stinging undiluted surfer goofiness deviation starved", }, @@ -64,7 +61,7 @@ func TestSignature_Sign(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { s := &Signature{} - got := s.Sign(tt.args.payload, tt.args.accountType, tt.args.accountAddress, tt.args.seed) + got := s.Sign(tt.args.payload, tt.args.accountAddress, tt.args.seed) if !reflect.DeepEqual(got, tt.want) { t.Errorf("Signature.Sign() = %v, want %v", got, tt.want) } @@ -107,7 +104,6 @@ func TestSignature_VerifySignature(t *testing.T) { type args struct { payload []byte signature []byte - accountType uint32 accountAddress string } tests := []struct { @@ -119,9 +115,8 @@ func TestSignature_VerifySignature(t *testing.T) { name: "VerifySignature:success", args: args{ payload: []byte{12, 43, 65, 65, 12, 123, 43, 12, 1, 24, 5, 5, 12, 54}, - accountType: 0, accountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - signature: []byte{42, 62, 47, 200, 180, 101, 85, 204, 179, 147, 143, 68, 30, 111, 6, 94, 81, 248, 219, 43, 90, 6, 167, + signature: []byte{0, 0, 0, 0, 42, 62, 47, 200, 180, 101, 85, 204, 179, 147, 143, 68, 30, 111, 6, 94, 81, 248, 219, 43, 90, 6, 167, 45, 132, 96, 130, 0, 153, 244, 159, 137, 159, 113, 78, 9, 164, 154, 213, 255, 17, 206, 153, 156, 176, 206, 33, 103, 72, 182, 228, 148, 234, 15, 176, 243, 50, 221, 106, 152, 53, 54, 173, 15}, }, @@ -131,9 +126,8 @@ func TestSignature_VerifySignature(t *testing.T) { name: "VerifySignature:success-{default}", args: args{ payload: []byte{12, 43, 65, 65, 12, 123, 43, 12, 1, 24, 5, 5, 12, 54}, - accountType: 10000, accountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - signature: []byte{42, 62, 47, 200, 180, 101, 85, 204, 179, 147, 143, 68, 30, 111, 6, 94, 81, 248, 219, 43, 90, 6, 167, + signature: []byte{0, 0, 0, 0, 42, 62, 47, 200, 180, 101, 85, 204, 179, 147, 143, 68, 30, 111, 6, 94, 81, 248, 219, 43, 90, 6, 167, 45, 132, 96, 130, 0, 153, 244, 159, 137, 159, 113, 78, 9, 164, 154, 213, 255, 17, 206, 153, 156, 176, 206, 33, 103, 72, 182, 228, 148, 234, 15, 176, 243, 50, 221, 106, 152, 53, 54, 173, 15}, }, @@ -143,7 +137,7 @@ func TestSignature_VerifySignature(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { s := &Signature{} - if got := s.VerifySignature(tt.args.payload, tt.args.signature, tt.args.accountType, tt.args.accountAddress); got != tt.want { + if got := s.VerifySignature(tt.args.payload, tt.args.signature, tt.args.accountAddress); got != tt.want { t.Errorf("Signature.VerifySignature() = %v, want %v", got, tt.want) } }) diff --git a/core/service/blockCoreService.go b/core/service/blockCoreService.go index eaf0d8054..91b639de9 100644 --- a/core/service/blockCoreService.go +++ b/core/service/blockCoreService.go @@ -305,7 +305,6 @@ func (bs *BlockService) GetGenesisBlock() (*model.Block, error) { &lastBlock.SmithScale, &lastBlock.PayloadLength, &lastBlock.PayloadHash, - &lastBlock.BlocksmithAddressLength, &lastBlock.BlocksmithAddress, &lastBlock.TotalAmount, &lastBlock.TotalFee, @@ -340,8 +339,8 @@ func (bs *BlockService) GetBlocks() ([]*model.Block, error) { for rows.Next() { var block model.Block err = rows.Scan(&block.ID, &block.PreviousBlockHash, &block.Height, &block.Timestamp, &block.BlockSeed, &block.BlockSignature, - &block.CumulativeDifficulty, &block.SmithScale, &block.PayloadLength, &block.PayloadHash, &block.BlocksmithAddressLength, - &block.BlocksmithAddress, &block.TotalAmount, &block.TotalFee, &block.TotalCoinBase, &block.Version) + &block.CumulativeDifficulty, &block.SmithScale, &block.PayloadLength, &block.PayloadHash, &block.BlocksmithAddress, + &block.TotalAmount, &block.TotalFee, &block.TotalCoinBase, &block.Version) if err != nil { return nil, err } @@ -500,9 +499,6 @@ func (bs *BlockService) CheckSignatureBlock(block *model.Block) bool { if err != nil { return false } - if err != nil { - return false - } return bs.Signature.VerifySignature(blockUnsignedByte, block.GetBlockSignature(), block.GetBlocksmithAddress()) } return false diff --git a/core/service/blockCoreService_test.go b/core/service/blockCoreService_test.go index e6f695037..7d852db14 100644 --- a/core/service/blockCoreService_test.go +++ b/core/service/blockCoreService_test.go @@ -62,7 +62,6 @@ func (*mockSignature) SignByNode(payload []byte, nodeSeed string) []byte { } func (*mockSignature) VerifySignature( payload, signature []byte, - accountType uint32, accountAddress string, ) bool { return true @@ -117,34 +116,34 @@ func (*mockQueryExecutorSuccess) ExecuteSelect(qe string, args ...interface{}) ( defer db.Close() switch qe { case "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height = 0": + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height = 0": mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ "ID", "PreviousBlockHash", "Height", "Timestamp", "BlockSeed", "BlockSignature", "CumulativeDifficulty", - "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithID", "TotalAmount", "TotalFee", "TotalCoinBase", + "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithAddress", "TotalAmount", "TotalFee", "TotalCoinBase", "Version"}, - ).AddRow(1, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, []byte{}, 0, 0, 0, 1)) + ).AddRow(1, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, "BCZ", 0, 0, 0, 1)) case "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block ORDER BY " + + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block ORDER BY " + "height DESC LIMIT 1": mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ "ID", "PreviousBlockHash", "Height", "Timestamp", "BlockSeed", "BlockSignature", "CumulativeDifficulty", - "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithID", "TotalAmount", "TotalFee", "TotalCoinBase", + "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithAddress", "TotalAmount", "TotalFee", "TotalCoinBase", "Version"}, - ).AddRow(1, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, []byte{}, 0, 0, 0, 1)) + ).AddRow(1, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, "BCZ", 0, 0, 0, 1)) case "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block " + + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block " + "WHERE height = 0 LIMIT 1": mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ "ID", "PreviousBlockHash", "Height", "Timestamp", "BlockSeed", "BlockSignature", "CumulativeDifficulty", - "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithID", "TotalAmount", "TotalFee", "TotalCoinBase", "Version"}). - AddRow(1, []byte{}, 0, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, []byte{}, 0, 0, 0, 1)) + "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithAddress", "TotalAmount", "TotalFee", "TotalCoinBase", "Version"}). + AddRow(1, []byte{}, 0, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, "BCZ", 0, 0, 0, 1)) case "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height >= 0 " + + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height >= 0 " + "LIMIT 100": mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ "ID", "PreviousBlockHash", "Height", "Timestamp", "BlockSeed", "BlockSignature", "CumulativeDifficulty", - "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithID", "TotalAmount", "TotalFee", "TotalCoinBase", "Version"}). - AddRow(1, []byte{}, 0, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, []byte{}, 0, 0, 0, 1)) + "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithAddress", "TotalAmount", "TotalFee", "TotalCoinBase", "Version"}). + AddRow(1, []byte{}, 0, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, "BCZ", 0, 0, 0, 1)) } rows, _ := db.Query(qe) @@ -218,7 +217,7 @@ func TestBlockService_NewBlock(t *testing.T) { version uint32 previousBlockHash []byte blockSeed []byte - blocksmithID []byte + blocksmithAddress string hash string previousBlockHeight uint32 timestamp int64 @@ -246,7 +245,7 @@ func TestBlockService_NewBlock(t *testing.T) { version: 1, previousBlockHash: []byte{}, blockSeed: []byte{}, - blocksmithID: []byte{}, + blocksmithAddress: "", hash: "hash", previousBlockHeight: 0, timestamp: 15875392, @@ -259,18 +258,19 @@ func TestBlockService_NewBlock(t *testing.T) { secretPhrase: "secretphrase", }, want: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 15875392, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + PayloadLength: 0, + BlockSignature: []byte{}, }, }, } @@ -289,7 +289,7 @@ func TestBlockService_NewBlock(t *testing.T) { tt.args.version, tt.args.previousBlockHash, tt.args.blockSeed, - tt.args.blocksmithID, + tt.args.blocksmithAddress, tt.args.hash, tt.args.previousBlockHeight, tt.args.timestamp, @@ -321,7 +321,7 @@ func TestBlockService_NewGenesisBlock(t *testing.T) { version uint32 previousBlockHash []byte blockSeed []byte - blocksmithID []byte + blocksmithAddress string hash string previousBlockHeight uint32 timestamp int64 @@ -351,7 +351,7 @@ func TestBlockService_NewGenesisBlock(t *testing.T) { version: 1, previousBlockHash: []byte{}, blockSeed: []byte{}, - blocksmithID: []byte{}, + blocksmithAddress: "", hash: "hash", previousBlockHeight: 0, timestamp: 15875392, @@ -366,20 +366,21 @@ func TestBlockService_NewGenesisBlock(t *testing.T) { genesisSignature: []byte{}, }, want: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 8, - SmithScale: 0, - CumulativeDifficulty: "1", - BlockSignature: []byte{}, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 15875392, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + PayloadLength: 8, + SmithScale: 0, + CumulativeDifficulty: "1", + BlockSignature: []byte{}, }, }, } @@ -398,7 +399,7 @@ func TestBlockService_NewGenesisBlock(t *testing.T) { tt.args.version, tt.args.previousBlockHash, tt.args.blockSeed, - tt.args.blocksmithID, + tt.args.blocksmithAddress, tt.args.hash, tt.args.previousBlockHeight, tt.args.timestamp, @@ -570,34 +571,36 @@ func TestBlockService_PushBlock(t *testing.T) { }, args: args{ previousBlock: &model.Block{ - ID: 0, - SmithScale: 10, - Timestamp: 10000, - CumulativeDifficulty: "10000", - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - BlockSignature: []byte{}, + ID: 0, + SmithScale: 10, + Timestamp: 10000, + CumulativeDifficulty: "10000", + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + BlockSignature: []byte{}, }, block: &model.Block{ - ID: 1, - Timestamp: 12000, - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - BlockSignature: []byte{}, + ID: 1, + Timestamp: 12000, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + BlockSignature: []byte{}, }, }, wantErr: false, @@ -615,31 +618,33 @@ func TestBlockService_PushBlock(t *testing.T) { }, args: args{ previousBlock: &model.Block{ - ID: 0, - SmithScale: 10, - Timestamp: 10000, - CumulativeDifficulty: "10000", - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - BlockSignature: []byte{}, + ID: 0, + SmithScale: 10, + Timestamp: 10000, + CumulativeDifficulty: "10000", + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + BlockSignature: []byte{}, }, block: &model.Block{ - ID: 1, - Timestamp: 12000, - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, + ID: 1, + Timestamp: 12000, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, Transactions: []*model.Transaction{ { Height: 0, @@ -695,21 +700,22 @@ func TestBlockService_GetLastBlock(t *testing.T) { BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), }, want: &model.Block{ - ID: 1, - PreviousBlockHash: []byte{}, - Height: 1, - Timestamp: 10000, - BlockSeed: []byte{}, - BlockSignature: []byte{}, - CumulativeDifficulty: "", - SmithScale: 1, - PayloadLength: 2, - PayloadHash: []byte{}, - BlocksmithID: []byte{}, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{}, + BlockSignature: []byte{}, + CumulativeDifficulty: "", + SmithScale: 1, + PayloadLength: 2, + PayloadHash: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "BCZ", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Version: 1, }, wantErr: false, }, @@ -785,21 +791,22 @@ func TestBlockService_GetGenesisBlock(t *testing.T) { BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), }, want: &model.Block{ - ID: 1, - PreviousBlockHash: []byte{}, - Height: 0, - Timestamp: 10000, - BlockSeed: []byte{}, - BlockSignature: []byte{}, - CumulativeDifficulty: "", - SmithScale: 1, - PayloadLength: 2, - PayloadHash: []byte{}, - BlocksmithID: []byte{}, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{}, + Height: 0, + Timestamp: 10000, + BlockSeed: []byte{}, + BlockSignature: []byte{}, + CumulativeDifficulty: "", + SmithScale: 1, + PayloadLength: 2, + PayloadHash: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "BCZ", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Version: 1, }, wantErr: false, }, @@ -876,21 +883,22 @@ func TestBlockService_GetBlocks(t *testing.T) { }, want: []*model.Block{ { - ID: 1, - PreviousBlockHash: []byte{}, - Height: 0, - Timestamp: 10000, - BlockSeed: []byte{}, - BlockSignature: []byte{}, - CumulativeDifficulty: "", - SmithScale: 1, - PayloadLength: 2, - PayloadHash: []byte{}, - BlocksmithID: []byte{}, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{}, + Height: 0, + Timestamp: 10000, + BlockSeed: []byte{}, + BlockSignature: []byte{}, + CumulativeDifficulty: "", + SmithScale: 1, + PayloadLength: 2, + PayloadHash: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "BCZ", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Version: 1, }, }, wantErr: false, @@ -1079,10 +1087,10 @@ func TestBlockService_GenerateBlock(t *testing.T) { ActionTypeSwitcher transaction.TypeActionSwitcher } type args struct { - previousBlock *model.Block - secretPhrase string - timestamp int64 - blockSmithAccountID []byte + previousBlock *model.Block + secretPhrase string + timestamp int64 + blockSmithAccountAddress string } tests := []struct { name string @@ -1101,22 +1109,23 @@ func TestBlockService_GenerateBlock(t *testing.T) { }, args: args{ previousBlock: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 12344587645, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 12344587645, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + PayloadLength: 0, + BlockSignature: []byte{}, }, - secretPhrase: "phasepress", - timestamp: 12344587645, - blockSmithAccountID: []byte{1, 2, 4}, + secretPhrase: "phasepress", + timestamp: 12344587645, + blockSmithAccountAddress: "BCZ", }, wantErr: true, }, @@ -1130,22 +1139,23 @@ func TestBlockService_GenerateBlock(t *testing.T) { }, args: args{ previousBlock: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 12344587645, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 12344587645, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + PayloadLength: 0, + BlockSignature: []byte{}, }, - secretPhrase: "pharsepress", - timestamp: 12344587645, - blockSmithAccountID: []byte{1, 2, 4}, + secretPhrase: "pharsepress", + timestamp: 12344587645, + blockSmithAccountAddress: "BCZ", }, wantErr: true, }, @@ -1166,22 +1176,23 @@ func TestBlockService_GenerateBlock(t *testing.T) { }, args: args{ previousBlock: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 12344587645, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 12344587645, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + PayloadLength: 0, + BlockSignature: []byte{}, }, - secretPhrase: "", - timestamp: 12345678, - blockSmithAccountID: []byte{1, 2, 4}, + secretPhrase: "", + timestamp: 12345678, + blockSmithAccountAddress: "BCZ", }, wantErr: false, }, @@ -1202,7 +1213,7 @@ func TestBlockService_GenerateBlock(t *testing.T) { tt.args.previousBlock, tt.args.secretPhrase, tt.args.timestamp, - tt.args.blockSmithAccountID, + tt.args.blockSmithAccountAddress, ) if (err != nil) != tt.wantErr { t.Errorf("BlockService.GenerateBlock() error = %v, wantErr %v", err, tt.wantErr) @@ -1298,7 +1309,7 @@ func (*mockQueryExecutorCheckGenesisTrue) ExecuteSelect(qe string, args ...inter "ID", "PreviousBlockHash", "Height", "Timestamp", "BlockSeed", "BlockSignature", "CumulativeDifficulty", "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithID", "TotalAmount", "TotalFee", "TotalCoinBase", "Version", - }).AddRow(4545420970999433273, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, []byte{}, 0, 0, 0, 1)) + }).AddRow(-1360700853772335847, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, []byte{}, 0, 0, 0, 1)) return db.Query("") } @@ -1392,62 +1403,6 @@ func TestBlockService_CheckSignatureBlock(t *testing.T) { }, want: false, }, - { - name: "wantFalse::GetAddressFiled", - fields: fields{ - Chaintype: &chaintype.MainChain{}, - QueryExecutor: &mockQueryExecutorSuccess{}, - BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), - MempoolQuery: query.NewMempoolQuery(&chaintype.MainChain{}), - TransactionQuery: query.NewTransactionQuery(&chaintype.MainChain{}), - Signature: &mockSignature{}, - }, - args: args{ - block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: nil, - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, - }, - }, - want: false, - }, - { - name: "wantFalse::GetAddressFiled", - fields: fields{ - Chaintype: &chaintype.MainChain{}, - QueryExecutor: &mockQueryExecutorSuccess{}, - BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), - MempoolQuery: query.NewMempoolQuery(&chaintype.MainChain{}), - TransactionQuery: query.NewTransactionQuery(&chaintype.MainChain{}), - Signature: &mockSignature{}, - }, - args: args{ - block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: nil, - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, - }, - }, - want: false, - }, { name: "wantTrue::VerifySignature", fields: fields{ @@ -1460,18 +1415,19 @@ func TestBlockService_CheckSignatureBlock(t *testing.T) { }, args: args{ block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: make([]byte, 32), - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: uint32(len([]byte("BCZ"))), + BlocksmithAddress: "BCZ", + Timestamp: 15875392, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + PayloadLength: 0, + BlockSignature: []byte{}, }, }, want: true, @@ -1530,22 +1486,23 @@ func TestBlockService_ReceivedBlockListener(t *testing.T) { }, args: args{ &model.Block{ - ID: 0, - Height: 0, - Version: 1, - CumulativeDifficulty: "", - SmithScale: 0, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: make([]byte, 32), - Timestamp: 12345678, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, + ID: 0, + Height: 0, + Version: 1, + CumulativeDifficulty: "", + SmithScale: 0, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: uint32(len([]byte("BCZ"))), + BlocksmithAddress: "BCZ", + Timestamp: 12345678, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + PayloadLength: 0, + BlockSignature: []byte{}, }, }, want: observer.Listener{ @@ -1563,22 +1520,23 @@ func TestBlockService_ReceivedBlockListener(t *testing.T) { }, args: args{ &model.Block{ - ID: 0, - Height: 0, - Version: 1, - CumulativeDifficulty: "", - SmithScale: 0, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: make([]byte, 32), - Timestamp: 12345678, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - PayloadLength: 0, - BlockSignature: []byte{}, + ID: 0, + Height: 0, + Version: 1, + CumulativeDifficulty: "", + SmithScale: 0, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: uint32(len([]byte("BCZ"))), + BlocksmithAddress: "BCZ", + Timestamp: 12345678, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + PayloadLength: 0, + BlockSignature: []byte{}, }, }, want: observer.Listener{ @@ -1647,21 +1605,22 @@ func TestBlockService_GetBlockByHeight(t *testing.T) { BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), }, want: &model.Block{ - ID: 1, - PreviousBlockHash: []byte{}, - Height: 1, - Timestamp: 10000, - BlockSeed: []byte{}, - BlockSignature: []byte{}, - CumulativeDifficulty: "", - SmithScale: 1, - PayloadLength: 2, - PayloadHash: []byte{}, - BlocksmithID: []byte{}, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{}, + BlockSignature: []byte{}, + CumulativeDifficulty: "", + SmithScale: 1, + PayloadLength: 2, + PayloadHash: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "BCZ", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Version: 1, }, wantErr: false, }, diff --git a/core/service/mempoolCoreService_test.go b/core/service/mempoolCoreService_test.go index c89b9ca8c..b296bd2a9 100644 --- a/core/service/mempoolCoreService_test.go +++ b/core/service/mempoolCoreService_test.go @@ -34,11 +34,11 @@ func (*mockMempoolQueryExecutorSuccess) ExecuteSelect(qe string, args ...interfa case "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_id, recipient_account_id FROM mempool": mockedRows := sqlmock.NewRows([]string{"id", "fee_per_byte", "arrival_timestamp", "transaction_bytes", "sender_account_id", "recipient_account_id"}) - mockedRows.AddRow(1, 1, 1562893305, getTestSignedMempoolTransaction(1, 1562893305).TransactionBytes, []byte{1}, []byte{2}) - mockedRows.AddRow(2, 10, 1562893304, getTestSignedMempoolTransaction(2, 1562893304).TransactionBytes, []byte{1}, []byte{2}) - mockedRows.AddRow(3, 1, 1562893302, getTestSignedMempoolTransaction(3, 1562893302).TransactionBytes, []byte{1}, []byte{2}) - mockedRows.AddRow(4, 100, 1562893306, getTestSignedMempoolTransaction(4, 1562893306).TransactionBytes, []byte{1}, []byte{2}) - mockedRows.AddRow(5, 5, 1562893303, getTestSignedMempoolTransaction(5, 1562893303).TransactionBytes, []byte{1}, []byte{2}) + mockedRows.AddRow(1, 1, 1562893305, getTestSignedMempoolTransaction(1, 1562893305).TransactionBytes, "A", "B") + mockedRows.AddRow(2, 10, 1562893304, getTestSignedMempoolTransaction(2, 1562893304).TransactionBytes, "A", "B") + mockedRows.AddRow(3, 1, 1562893302, getTestSignedMempoolTransaction(3, 1562893302).TransactionBytes, "A", "B") + mockedRows.AddRow(4, 100, 1562893306, getTestSignedMempoolTransaction(4, 1562893306).TransactionBytes, "A", "B") + mockedRows.AddRow(5, 5, 1562893303, getTestSignedMempoolTransaction(5, 1562893303).TransactionBytes, "A", "B") mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(mockedRows) case getTxByIDQuery: return nil, errors.New("MempoolTransactionNotFound") @@ -95,22 +95,22 @@ func (*mockMempoolQueryExecutorFail) ExecuteTransaction(qe string, args ...inter func buildTransaction(timestamp int64, sender, recipient string) *model.Transaction { return &model.Transaction{ - Version: 1, - ID: 2774809487, - BlockID: 1, - Height: 1, - SenderAccountType: 0, - SenderAccountAddress: sender, - RecipientAccountType: 0, - RecipientAccountAddress: recipient, - TransactionType: 0, - Fee: 1, - Timestamp: timestamp, - TransactionHash: make([]byte, 32), - TransactionBodyLength: 0, - TransactionBodyBytes: make([]byte, 0), - TransactionBody: nil, - Signature: make([]byte, 64), + Version: 1, + ID: 2774809487, + BlockID: 1, + Height: 1, + SenderAccountAddressLength: uint32(len([]byte(sender))), + SenderAccountAddress: sender, + RecipientAccountAddressLength: uint32(len([]byte(recipient))), + RecipientAccountAddress: recipient, + TransactionType: 0, + Fee: 1, + Timestamp: timestamp, + TransactionHash: make([]byte, 32), + TransactionBodyLength: 0, + TransactionBodyBytes: make([]byte, 0), + TransactionBody: nil, + Signature: make([]byte, 64), } } @@ -118,12 +118,12 @@ func getTestSignedMempoolTransaction(id, timestamp int64) *model.MempoolTransact tx := buildTransaction(timestamp, "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN") txBytes, _ := util.GetTransactionBytes(tx, true) return &model.MempoolTransaction{ - ID: id, - FeePerByte: 1, - ArrivalTimestamp: timestamp, - TransactionBytes: txBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: id, + FeePerByte: 1, + ArrivalTimestamp: timestamp, + TransactionBytes: txBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", } } @@ -187,44 +187,44 @@ func TestMempoolService_GetMempoolTransactions(t *testing.T) { }, want: []*model.MempoolTransaction{ { - ID: 1, - FeePerByte: 1, - ArrivalTimestamp: 1562893305, - TransactionBytes: getTestSignedMempoolTransaction(1, 1562893305).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 1, + FeePerByte: 1, + ArrivalTimestamp: 1562893305, + TransactionBytes: getTestSignedMempoolTransaction(1, 1562893305).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, { - ID: 2, - FeePerByte: 10, - ArrivalTimestamp: 1562893304, - TransactionBytes: getTestSignedMempoolTransaction(2, 1562893304).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 2, + FeePerByte: 10, + ArrivalTimestamp: 1562893304, + TransactionBytes: getTestSignedMempoolTransaction(2, 1562893304).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, { - ID: 3, - FeePerByte: 1, - ArrivalTimestamp: 1562893302, - TransactionBytes: getTestSignedMempoolTransaction(3, 1562893302).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 3, + FeePerByte: 1, + ArrivalTimestamp: 1562893302, + TransactionBytes: getTestSignedMempoolTransaction(3, 1562893302).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, { - ID: 4, - FeePerByte: 100, - ArrivalTimestamp: 1562893306, - TransactionBytes: getTestSignedMempoolTransaction(4, 1562893306).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 4, + FeePerByte: 100, + ArrivalTimestamp: 1562893306, + TransactionBytes: getTestSignedMempoolTransaction(4, 1562893306).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, { - ID: 5, - FeePerByte: 5, - ArrivalTimestamp: 1562893303, - TransactionBytes: getTestSignedMempoolTransaction(5, 1562893303).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 5, + FeePerByte: 5, + ArrivalTimestamp: 1562893303, + TransactionBytes: getTestSignedMempoolTransaction(5, 1562893303).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, }, wantErr: false, @@ -351,44 +351,44 @@ func TestMempoolService_SelectTransactionsFromMempool(t *testing.T) { }, want: []*model.MempoolTransaction{ { - ID: 4, - FeePerByte: 100, - ArrivalTimestamp: 1562893306, - TransactionBytes: getTestSignedMempoolTransaction(4, 1562893306).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 4, + FeePerByte: 100, + ArrivalTimestamp: 1562893306, + TransactionBytes: getTestSignedMempoolTransaction(4, 1562893306).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, { - ID: 2, - FeePerByte: 10, - ArrivalTimestamp: 1562893304, - TransactionBytes: getTestSignedMempoolTransaction(2, 1562893304).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 2, + FeePerByte: 10, + ArrivalTimestamp: 1562893304, + TransactionBytes: getTestSignedMempoolTransaction(2, 1562893304).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, { - ID: 5, - FeePerByte: 5, - ArrivalTimestamp: 1562893303, - TransactionBytes: getTestSignedMempoolTransaction(5, 1562893303).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 5, + FeePerByte: 5, + ArrivalTimestamp: 1562893303, + TransactionBytes: getTestSignedMempoolTransaction(5, 1562893303).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, { - ID: 3, - FeePerByte: 1, - ArrivalTimestamp: 1562893302, - TransactionBytes: getTestSignedMempoolTransaction(3, 1562893302).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 3, + FeePerByte: 1, + ArrivalTimestamp: 1562893302, + TransactionBytes: getTestSignedMempoolTransaction(3, 1562893302).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, { - ID: 1, - FeePerByte: 1, - ArrivalTimestamp: 1562893305, - TransactionBytes: getTestSignedMempoolTransaction(1, 1562893305).TransactionBytes, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 1, + FeePerByte: 1, + ArrivalTimestamp: 1562893305, + TransactionBytes: getTestSignedMempoolTransaction(1, 1562893305).TransactionBytes, + SenderAccountAddress: "A", + RecipientAccountAddress: "B", }, }, wantErr: false, diff --git a/core/smith/blockchainProcessor.go b/core/smith/blockchainProcessor.go index 82b774086..b75d48484 100644 --- a/core/smith/blockchainProcessor.go +++ b/core/smith/blockchainProcessor.go @@ -69,7 +69,7 @@ func (*BlockchainProcessor) CalculateSmith(lastBlock *model.Block, generator *Bl Balance: 1000000000, SpendableBalance: 1000000000, } - if len(account.AccountAddress) == 0 { + if account.AccountAddress == "" { generator.Balance = big.NewInt(0) } else { accountEffectiveBalance := account.GetBalance() diff --git a/core/util/blockUtil_test.go b/core/util/blockUtil_test.go index c6753a049..e02888b5f 100644 --- a/core/util/blockUtil_test.go +++ b/core/util/blockUtil_test.go @@ -116,46 +116,49 @@ func TestCalculateSmithScale(t *testing.T) { name: "CalculateSmithScale", args: args{ previousBlock: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - CumulativeDifficulty: "100000", - SmithScale: 108080, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 15875392, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + CumulativeDifficulty: "100000", + SmithScale: 108080, }, block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 15875392, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, }, smithingDelayTime: 10, }, want: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - CumulativeDifficulty: "341353517378119", - SmithScale: 54040, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 15875392, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + CumulativeDifficulty: "341353517378119", + SmithScale: 54040, }, }, } @@ -181,43 +184,45 @@ func TestGetBlockID(t *testing.T) { name: "GetBlockID:one", args: args{ block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{}, - BlockSeed: []byte{}, - BlocksmithID: []byte{}, - Timestamp: 15875392, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - CumulativeDifficulty: "341353517378119", - BlockSignature: []byte{}, - SmithScale: 54040, + Version: 1, + PreviousBlockHash: []byte{}, + BlockSeed: []byte{}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 15875392, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + CumulativeDifficulty: "341353517378119", + BlockSignature: []byte{}, + SmithScale: 54040, }, }, - want: -3024391177923659831, + want: 2302495433703223211, }, { name: "GetBlockID:two", args: args{ block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, - BlockSeed: []byte{2, 65, 76, 32, 76, 12, 12, 34, 65, 76}, - BlocksmithID: []byte{12, 43, 65, 32, 56}, - Timestamp: 15875592, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - CumulativeDifficulty: "355353517378119", - BlockSignature: []byte{}, - SmithScale: 48985, + Version: 1, + PreviousBlockHash: []byte{1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, + BlockSeed: []byte{2, 65, 76, 32, 76, 12, 12, 34, 65, 76}, + BlocksmithAddressLength: 0, + BlocksmithAddress: "", + Timestamp: 15875592, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + CumulativeDifficulty: "355353517378119", + BlockSignature: []byte{}, + SmithScale: 48985, }, }, - want: 3300349166301930278, + want: -3939633329194296199, }, } for _, tt := range tests { @@ -244,67 +249,72 @@ func TestGetBlockByte(t *testing.T) { name: "GetBlockByte:one", args: args{ block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, - BlockSeed: []byte{2, 65, 76, 32, 76, 12, 12, 34, 65, 76}, - BlocksmithID: []byte{12, 43, 65, 32, 56}, - Timestamp: 15875592, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - CumulativeDifficulty: "355353517378119", - SmithScale: 48985, + Version: 1, + PreviousBlockHash: []byte{1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, + BlockSeed: []byte{2, 65, 76, 32, 76, 12, 12, 34, 65, 76}, + BlocksmithAddressLength: uint32(len([]byte("BCZ"))), + BlocksmithAddress: "BCZ", + Timestamp: 15875592, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + CumulativeDifficulty: "355353517378119", + SmithScale: 48985, }, sign: false, }, - want: []byte{1, 0, 0, 0, 8, 62, 242, 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, 12, 43, 65, 32, 56, 2, 65, 76, 32, 76, 12, 12, 34, 65, - 76, 1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, + want: []byte{1, 0, 0, 0, 8, 62, 242, 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, 3, 0, 0, 0, 66, 67, 90, 2, 65, 76, 32, 76, 12, 12, 34, 65, 76, 1, + 2, 4, 5, 67, 89, 86, 3, 6, 22}, wantErr: false, }, { name: "GetBlockByte:withSignature", args: args{ block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, - BlockSeed: []byte{2, 65, 76, 32, 76, 12, 12, 34, 65, 76}, - BlocksmithID: []byte{12, 43, 65, 32, 56}, - Timestamp: 15875592, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - CumulativeDifficulty: "355353517378119", - BlockSignature: []byte{1, 3, 4, 54, 65, 76, 3, 3, 54, 12, 5, 64, 23, 12, 21}, - SmithScale: 48985, + Version: 1, + PreviousBlockHash: []byte{1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, + BlockSeed: []byte{2, 65, 76, 32, 76, 12, 12, 34, 65, 76}, + BlocksmithAddressLength: uint32(len([]byte("BCZ"))), + BlocksmithAddress: "BCZ", + Timestamp: 15875592, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + CumulativeDifficulty: "355353517378119", + BlockSignature: []byte{1, 3, 4, 54, 65, 76, 3, 3, 54, 12, 5, 64, 23, 12, 21}, + SmithScale: 48985, }, sign: true, }, - want: []byte{1, 0, 0, 0, 8, 62, 242, 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, 12, 43, 65, 32, 56, 2, 65, 76, 32, 76, 12, 12, 34, 65, 76, 1, 2, 4, - 5, 67, 89, 86, 3, 6, 22, 1, 3, 4, 54, 65, 76, 3, 3, 54, 12, 5, 64, 23, 12, 21}, + want: []byte{ + 1, 0, 0, 0, 8, 62, 242, 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, 3, 0, 0, 0, 66, 67, 90, 2, 65, 76, 32, 76, 12, 12, 34, 65, 76, 1, 2, 4, 5, 67, 89, 86, + 3, 6, 22, 1, 3, 4, 54, 65, 76, 3, 3, 54, 12, 5, 64, 23, 12, 21, + }, wantErr: false, }, { name: "GetBlockByte:error-{sign true without signature}", args: args{ block: &model.Block{ - Version: 1, - PreviousBlockHash: []byte{1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, - BlockSeed: []byte{2, 65, 76, 32, 76, 12, 12, 34, 65, 76}, - BlocksmithID: []byte{12, 43, 65, 32, 56}, - Timestamp: 15875592, - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Transactions: []*model.Transaction{}, - PayloadHash: []byte{}, - CumulativeDifficulty: "355353517378119", - SmithScale: 48985, + Version: 1, + PreviousBlockHash: []byte{1, 2, 4, 5, 67, 89, 86, 3, 6, 22}, + BlockSeed: []byte{2, 65, 76, 32, 76, 12, 12, 34, 65, 76}, + BlocksmithAddressLength: uint32(len([]byte("BCZ"))), + BlocksmithAddress: "BCZ", + Timestamp: 15875592, + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Transactions: []*model.Transaction{}, + PayloadHash: []byte{}, + CumulativeDifficulty: "355353517378119", + SmithScale: 48985, }, sign: true, }, From bcab96eb85b44e6b5ee45837796aa12b72ac4615 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 14:37:48 +0800 Subject: [PATCH 09/27] #134 remove address length in db --- common/database/migration.go | 1 - common/query/blockQuery.go | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/common/database/migration.go b/common/database/migration.go index 9e8ce704d..976ef06cf 100644 --- a/common/database/migration.go +++ b/common/database/migration.go @@ -90,7 +90,6 @@ func (m *Migration) Init() error { "block_signature" BLOB, "cumulative_difficulty" TEXT, "smith_scale" INTEGER, - "blocksmith_address_length" INTEGER, "blocksmith_address" VARCHAR(255), "total_amount" INTEGER, "total_fee" INTEGER, diff --git a/common/query/blockQuery.go b/common/query/blockQuery.go index 69ad08ec2..289181737 100644 --- a/common/query/blockQuery.go +++ b/common/query/blockQuery.go @@ -33,7 +33,7 @@ type ( func NewBlockQuery(chaintype contract.ChainType) *BlockQuery { return &BlockQuery{ Fields: []string{"id", "previous_block_hash", "height", "timestamp", "block_seed", "block_signature", "cumulative_difficulty", - "smith_scale", "payload_length", "payload_hash", "blocksmith_address_length", "blocksmith_address", "total_amount", "total_fee", + "smith_scale", "payload_length", "payload_hash", "blocksmith_address", "total_amount", "total_fee", "total_coinbase", "version", }, TableName: "block", @@ -88,7 +88,6 @@ func (*BlockQuery) ExtractModel(block *model.Block) []interface{} { block.SmithScale, block.PayloadLength, block.PayloadHash, - block.BlocksmithAddressLength, block.BlocksmithAddress, block.TotalAmount, block.TotalFee, @@ -102,7 +101,7 @@ func (*BlockQuery) BuildModel(blocks []*model.Block, rows *sql.Rows) []*model.Bl var block model.Block _ = rows.Scan(&block.ID, &block.PreviousBlockHash, &block.Height, &block.Timestamp, &block.BlockSeed, &block.BlockSignature, &block.CumulativeDifficulty, &block.SmithScale, &block.PayloadLength, - &block.PayloadHash, &block.BlocksmithAddressLength, &block.BlocksmithAddress, &block.TotalAmount, &block.TotalFee, + &block.PayloadHash, &block.BlocksmithAddress, &block.TotalAmount, &block.TotalFee, &block.TotalCoinBase, &block.Version) blocks = append(blocks, &block) } From 4574f99737e193a2a6de33f29175db49b7adcea5 Mon Sep 17 00:00:00 2001 From: astaphobia Date: Fri, 9 Aug 2019 15:31:21 +0800 Subject: [PATCH 10/27] refacored some codes for the new strategy --- api/service/blockApiService.go | 1 + api/service/blockApiService_test.go | 241 +++++++++++++++++--------- common/query/blockQuery.go | 21 ++- common/query/nodeRegistrationQuery.go | 2 +- 4 files changed, 177 insertions(+), 88 deletions(-) diff --git a/api/service/blockApiService.go b/api/service/blockApiService.go index ed61e1cd3..7d8abccfa 100644 --- a/api/service/blockApiService.go +++ b/api/service/blockApiService.go @@ -50,6 +50,7 @@ func (bs *BlockService) GetBlockByID(chainType contract.ChainType, id int64) (*m return nil, err } defer rows.Close() + bl = blockQuery.BuildModel(bl, rows) if len(bl) == 0 { return nil, errors.New("BlockNotFound") diff --git a/api/service/blockApiService_test.go b/api/service/blockApiService_test.go index bb7bb4edb..c2d97e49e 100644 --- a/api/service/blockApiService_test.go +++ b/api/service/blockApiService_test.go @@ -22,10 +22,6 @@ func ResetBlockService() { } type ( - mockQueryExecutorBlockByIDSuccess struct { - query.Executor - } - mockQueryExecutorBlockByIDFail struct { query.Executor } @@ -43,17 +39,6 @@ type ( } ) -func (*mockQueryExecutorBlockByIDSuccess) ExecuteSelect(qe string, args ...interface{}) (*sql.Rows, error) { - db, mock, _ := sqlmock.New() - defer db.Close() - mock.ExpectQuery(regexp.QuoteMeta(`SELECT`)).WillReturnRows(sqlmock.NewRows([]string{ - "ID", "PreviousBlockHash", "Height", "Timestamp", "BlockSeed", "BlockSignature", "CumulativeDifficulty", - "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithID", "TotalAmount", "TotalFee", "TotalCoinBase", - "Version"}).AddRow(1, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, []byte{}, 0, 0, 0, 1)) - rows, _ := db.Query(qe) - return rows, nil -} - func (*mockQueryExecutorBlockByIDFail) ExecuteSelect(qe string, args ...interface{}) (*sql.Rows, error) { return nil, errors.New("mockError:executeSelectFail") } @@ -85,7 +70,7 @@ func (*mockQueryExecutorGetBlocksFail) ExecuteSelect(qe string, args ...interfac return nil, errors.New("mockError:executeSelectFail") } -func TestNewBlockervice(t *testing.T) { +func TestNewBlockService(t *testing.T) { db, _, err := sqlmock.New() if err != nil { t.Fatalf("error while opening database connection") @@ -111,6 +96,40 @@ func TestNewBlockervice(t *testing.T) { } } +type ( + mockQueryGetBlockByIDSuccess struct { + query.Executor + } +) + +func (*mockQueryGetBlockByIDSuccess) ExecuteSelect(qStr string, args ...interface{}) (*sql.Rows, error) { + db, mock, _ := sqlmock.New() + defer db.Close() + + blockQ := query.NewBlockQuery(&chaintype.MainChain{}) + + mock.ExpectQuery(regexp.QuoteMeta(`SELECT`)).WillReturnRows( + sqlmock.NewRows(blockQ.Fields).AddRow( + 1, + []byte{1}, + 1, + 10000, + []byte{2}, + []byte{3}, + "cumulative", + 1, + 1, + []byte{4}, + 1, + "smithAddress", + 1, + 1, + 1, + 1, + ), + ) + return db.Query(qStr) +} func TestBlockService_GetBlockByID(t *testing.T) { type fields struct { Query query.ExecutorInterface @@ -129,7 +148,7 @@ func TestBlockService_GetBlockByID(t *testing.T) { { name: "GetBlockByID:success", fields: fields{ - Query: &mockQueryExecutorBlockByIDSuccess{}, + Query: &mockQueryGetBlockByIDSuccess{}, }, args: args{ chainType: &chaintype.MainChain{}, @@ -137,21 +156,22 @@ func TestBlockService_GetBlockByID(t *testing.T) { }, wantErr: false, want: &model.Block{ - ID: 1, - PreviousBlockHash: []byte{}, - Height: 1, - Timestamp: 10000, - BlockSeed: []byte{}, - BlockSignature: []byte{}, - CumulativeDifficulty: "", - SmithScale: 1, - PayloadLength: 2, - PayloadHash: []byte{}, - BlocksmithAddress: "", - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{1}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{2}, + BlockSignature: []byte{3}, + CumulativeDifficulty: "cumulative", + SmithScale: 1, + BlocksmithAddressLength: 1, + BlocksmithAddress: "smithAddress", + PayloadLength: 1, + PayloadHash: []byte{4}, + TotalAmount: 1, + TotalFee: 1, + TotalCoinBase: 1, + Version: 1, }, }, { @@ -190,12 +210,47 @@ func TestBlockService_GetBlockByID(t *testing.T) { return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("BlockService.GetBlockByID() = %v, want %v", got, tt.want) + t.Errorf("BlockService.GetBlockByID() got = \n%v, want = \n%v", got, tt.want) } }) } } +type ( + mockQueryGetBlockByHeightSuccess struct { + query.Executor + } +) + +func (*mockQueryGetBlockByHeightSuccess) ExecuteSelect(qStr string, args ...interface{}) (*sql.Rows, error) { + db, mock, _ := sqlmock.New() + defer db.Close() + + blockQ := query.NewBlockQuery(&chaintype.MainChain{}) + + mock.ExpectQuery(regexp.QuoteMeta(`SELECT`)).WillReturnRows( + sqlmock.NewRows(blockQ.Fields).AddRow( + 1, + []byte{1}, + 1, + 10000, + []byte{2}, + []byte{3}, + "cumulative", + 1, + 1, + []byte{4}, + 1, + "smithAddress", + 1, + 1, + 1, + 1, + ), + ) + return db.Query(qStr) +} + func TestBlockService_GetBlockByHeight(t *testing.T) { type fields struct { Query query.ExecutorInterface @@ -214,7 +269,7 @@ func TestBlockService_GetBlockByHeight(t *testing.T) { { name: "GetBlockByHeight:success", fields: fields{ - Query: &mockQueryExecutorBlockByIDSuccess{}, + Query: &mockQueryGetBlockByHeightSuccess{}, }, args: args{ chainType: &chaintype.MainChain{}, @@ -222,21 +277,22 @@ func TestBlockService_GetBlockByHeight(t *testing.T) { }, wantErr: false, want: &model.Block{ - ID: 1, - PreviousBlockHash: []byte{}, - Height: 1, - Timestamp: 10000, - BlockSeed: []byte{}, - BlockSignature: []byte{}, - CumulativeDifficulty: "", - SmithScale: 1, - PayloadLength: 2, - PayloadHash: []byte{}, - BlocksmithAddress: "", - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{1}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{2}, + BlockSignature: []byte{3}, + CumulativeDifficulty: "cumulative", + SmithScale: 1, + BlocksmithAddressLength: 1, + BlocksmithAddress: "smithAddress", + PayloadLength: 1, + PayloadHash: []byte{4}, + TotalAmount: 1, + TotalFee: 1, + TotalCoinBase: 1, + Version: 1, }, }, { @@ -281,6 +337,41 @@ func TestBlockService_GetBlockByHeight(t *testing.T) { } } +type ( + mockQueryGetBlocksSuccess struct { + query.Executor + } +) + +func (*mockQueryGetBlocksSuccess) ExecuteSelect(qStr string, args ...interface{}) (*sql.Rows, error) { + db, mock, _ := sqlmock.New() + defer db.Close() + + blockQ := query.NewBlockQuery(&chaintype.MainChain{}) + + mock.ExpectQuery(regexp.QuoteMeta(`SELECT`)).WillReturnRows( + sqlmock.NewRows(blockQ.Fields).AddRow( + 1, + []byte{1}, + 1, + 10000, + []byte{2}, + []byte{3}, + "cumulative", + 1, + 1, + []byte{4}, + 1, + "smithAddress", + 1, + 1, + 1, + 1, + ), + ) + return db.Query(qStr) +} + func TestBlockService_GetBlocks(t *testing.T) { type fields struct { Query query.ExecutorInterface @@ -300,7 +391,7 @@ func TestBlockService_GetBlocks(t *testing.T) { { name: "GetBlocks:success", fields: fields{ - Query: &mockQueryExecutorGetBlocksSuccess{}, + Query: &mockQueryGetBlocksSuccess{}, }, args: args{ chainType: &chaintype.MainChain{}, @@ -309,41 +400,25 @@ func TestBlockService_GetBlocks(t *testing.T) { }, want: &model.GetBlocksResponse{ Height: 1, - Count: 2, + Count: 1, Blocks: []*model.Block{ { - ID: 1, - PreviousBlockHash: []byte{}, - Height: 1, - Timestamp: 10000, - BlockSeed: []byte{}, - BlockSignature: []byte{}, - CumulativeDifficulty: "", - SmithScale: 1, - PayloadLength: 2, - PayloadHash: []byte{}, - BlocksmithAddress: "", - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Version: 1, - }, - { - ID: 1, - PreviousBlockHash: []byte{}, - Height: 2, - Timestamp: 10000, - BlockSeed: []byte{}, - BlockSignature: []byte{}, - CumulativeDifficulty: "", - SmithScale: 1, - PayloadLength: 2, - PayloadHash: []byte{}, - BlocksmithAddress: "", - TotalAmount: 0, - TotalFee: 0, - TotalCoinBase: 0, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{1}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{2}, + BlockSignature: []byte{3}, + CumulativeDifficulty: "cumulative", + SmithScale: 1, + BlocksmithAddressLength: 1, + BlocksmithAddress: "smithAddress", + PayloadLength: 1, + PayloadHash: []byte{4}, + TotalAmount: 1, + TotalFee: 1, + TotalCoinBase: 1, + Version: 1, }, }, }, diff --git a/common/query/blockQuery.go b/common/query/blockQuery.go index 0e54e6451..10c5c56bc 100644 --- a/common/query/blockQuery.go +++ b/common/query/blockQuery.go @@ -32,9 +32,23 @@ type ( // NewBlockQuery returns BlockQuery instance func NewBlockQuery(chaintype contract.ChainType) *BlockQuery { return &BlockQuery{ - Fields: []string{"id", "previous_block_hash", "height", "timestamp", "block_seed", "block_signature", "cumulative_difficulty", - "smith_scale", "payload_length", "payload_hash", "blocksmith_address_length", "blocksmith_address", "total_amount", "total_fee", - "total_coinbase", "version", + Fields: []string{ + "id", + "previous_block_hash", + "height", + "timestamp", + "block_seed", + "block_signature", + "cumulative_difficulty", + "smith_scale", + "blocksmith_address_length", + "blocksmith_address", + "total_amount", + "total_fee", + "total_coinbase", + "version", + "payload_length", + "payload_hash", }, TableName: "block", ChainType: chaintype, @@ -94,7 +108,6 @@ func (*BlockQuery) ExtractModel(block *model.Block) []interface{} { block.Version, block.PayloadLength, block.PayloadHash, - block.Transactions, } } diff --git a/common/query/nodeRegistrationQuery.go b/common/query/nodeRegistrationQuery.go index d1427a425..b8619b00e 100644 --- a/common/query/nodeRegistrationQuery.go +++ b/common/query/nodeRegistrationQuery.go @@ -81,7 +81,7 @@ func (nr *NodeRegistrationQuery) GetNodeRegistrationByNodePublicKey(nodePublicKe // GetNodeRegistrationByAccountID returns query string to get Node Registration by account public key func (nr *NodeRegistrationQuery) GetNodeRegistrationByAccountAddress(accountAddress string) (str string, args []interface{}) { - return fmt.Sprintf("SELECT %s FROM %s WHERE account_address = %d AND latest=1", + return fmt.Sprintf("SELECT %s FROM %s WHERE account_address = %s AND latest=1", strings.Join(nr.Fields, ", "), nr.getTableName(), accountAddress), []interface{}{accountAddress} } From c422a8fe26319818b57f057a8d6ebdffae43a8d9 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 15:33:29 +0800 Subject: [PATCH 11/27] #134 fix util test --- common/util/account_test.go | 104 ------------- common/util/transaction.go | 1 - common/util/transaction_test.go | 258 +++++++++++++++++--------------- 3 files changed, 135 insertions(+), 228 deletions(-) diff --git a/common/util/account_test.go b/common/util/account_test.go index 43bd69134..d54588241 100644 --- a/common/util/account_test.go +++ b/common/util/account_test.go @@ -1,41 +1,10 @@ package util import ( - "math" "reflect" "testing" ) -func TestGetAccountIDByPublicKey(t *testing.T) { - type args struct { - accountType uint32 - publicKey []byte - } - tests := []struct { - name string - args args - want []byte - }{ - { - name: "GetAccountIDByPublicKey:success", - args: args{ - accountType: 0, - 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{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 { - t.Run(tt.name, func(t *testing.T) { - if got := GetAccountIDByPublicKey(tt.args.accountType, tt.args.publicKey); !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetAccountIDByPublicKey() = %v, want %v", got, tt.want) - } - }) - } -} - func TestGetChecksumByte(t *testing.T) { type args struct { bytes []byte @@ -203,76 +172,3 @@ func TestGetPublicKeyFromAddress(t *testing.T) { }) } } - -func TestCreateAccountIDFromAddress(t *testing.T) { - type args struct { - accountType uint32 - address string - } - tests := []struct { - name string - args args - want []byte - }{ - { - name: "CreateAccountIDFromAddress:success", - args: args{ - accountType: 0, - address: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", - }, - want: []byte{136, 106, 141, 253, 44, 34, 145, 81, 166, 229, 33, 209, 150, 188, 204, 28, 239, 33, 152, 158, 4, 187, - 13, 109, 173, 223, 169, 232, 50, 200, 169, 25}, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := CreateAccountIDFromAddress(tt.args.accountType, tt.args.address); !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateAccountIDFromAddress() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestValidateAccountAddress(t *testing.T) { - type args struct { - accType uint32 - address string - } - tests := []struct { - name string - args args - wantErr bool - }{ - { - name: "TestValidateAccountAddress:Default", - args: args{ - accType: math.MaxUint32, - address: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", - }, - wantErr: true, - }, - { - name: "TestValidateAccountAddress:0:success", - args: args{ - accType: 0, - address: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", - }, - wantErr: false, - }, - { - name: "TestValidateAccountAddress:0:wantErr", - args: args{ - accType: 0, - address: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0", - }, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := ValidateAccountAddress(tt.args.accType, tt.args.address); (err != nil) != tt.wantErr { - t.Errorf("ValidateAccountAddress() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} diff --git a/common/util/transaction.go b/common/util/transaction.go index ffc220da2..fcb91d3f1 100644 --- a/common/util/transaction.go +++ b/common/util/transaction.go @@ -3,7 +3,6 @@ package util import ( "bytes" "errors" - "github.com/zoobc/zoobc-core/common/constant" "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/common/query" diff --git a/common/util/transaction_test.go b/common/util/transaction_test.go index f33e38d2f..da991fee6 100644 --- a/common/util/transaction_test.go +++ b/common/util/transaction_test.go @@ -22,14 +22,14 @@ type mockQueryExecutorSuccess struct { func (*mockQueryExecutorSuccess) ExecuteSelect(qe string, args ...interface{}) (*sql.Rows, error) { db, mock, _ := sqlmock.New() - getAccountBalanceByAccountID := "SELECT account_id,block_height,spendable_balance,balance,pop_revenue," + - "latest FROM account_balance WHERE account_id = ? AND latest = 1" + getAccountBalanceByAccountID := "SELECT account_address,block_height,spendable_balance,balance,pop_revenue," + + "latest FROM account_balance WHERE account_address = ? AND latest = 1" defer db.Close() switch qe { case getAccountBalanceByAccountID: mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ - "account_id", "block_height", "spendable_balance", "balance", "pop_revenue", "latest"}, - ).AddRow([]byte{}, 1, 10000, 10000, 0, 1)) + "account_address", "block_height", "spendable_balance", "balance", "pop_revenue", "latest"}, + ).AddRow("BCZ", 1, 10000, 10000, 0, 1)) default: return nil, nil } @@ -53,70 +53,73 @@ func TestGetTransactionBytes(t *testing.T) { name: "GetTransactionBytes:success", args: args{ transaction: &model.Transaction{ - 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}, + TransactionType: 2, + Version: 1, + Timestamp: 1562806389280, + SenderAccountAddressLength: uint32(len([]byte("BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7"))), + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountAddressLength: uint32(len([]byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"))), + 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, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 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, 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}, + want: []byte{ + 2, 0, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 44, 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, 44, + 0, 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{ - 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}, + Version: 1, + TransactionType: 2, + Timestamp: 1562806389280, + SenderAccountAddressLength: uint32(len([]byte("BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7"))), + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountAddressLength: uint32(len([]byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"))), + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionBodyLength: 8, + TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }, sign: false, }, - want: []byte{2, 0, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 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, 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}, + want: []byte{ + 2, 0, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 44, 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, 44, 0, 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, - 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}, + TransactionType: 2, + Version: 1, + Timestamp: 1562806389280, + SenderAccountAddressLength: uint32(len([]byte("BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7"))), + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountAddressLength: uint32(len([]byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"))), + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionBodyLength: 8, + TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }, sign: true, }, @@ -127,22 +130,24 @@ func TestGetTransactionBytes(t *testing.T) { name: "GetTransactionBytes:success-{without recipient}", args: args{ transaction: &model.Transaction{ - 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}, + Version: 1, + TransactionType: 2, + Timestamp: 1562806389280, + SenderAccountAddressLength: uint32(len([]byte("BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7"))), + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + Fee: 1000000, + TransactionBodyLength: 8, + TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }, sign: false, }, - want: []byte{2, 0, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 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, 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, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 44, 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, 0, 0, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, + 6, 7, 8, + }, wantErr: false, }, } @@ -174,62 +179,69 @@ func TestParseTransactionBytes(t *testing.T) { { name: "ParseTransactionBytes:success", args: args{ - transactionBytes: []byte{2, 0, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 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, 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}, + transactionBytes: []byte{ + 2, 0, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 44, 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, 44, + 0, 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{ - ID: -2622463497698940853, - Version: 1, - TransactionType: 2, - BlockID: 0, - Height: 0, - Timestamp: 1562806389280, - SenderAccountType: 0, - SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", - RecipientAccountType: 0, - RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", - Fee: 1000000, - TransactionHash: []byte{75, 232, 57, 223, 87, 35, 155, 219, 42, 153, 22, 92, 243, 248, 88, 113, 184, 206, 205, - 252, 121, 173, 28, 229, 21, 59, 40, 57, 89, 191, 91, 236}, + ID: 6829445217349326123, + Version: 1, + TransactionType: 2, + BlockID: 0, + Height: 0, + Timestamp: 1562806389280, + SenderAccountAddressLength: 44, + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountAddressLength: 44, + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionHash: []byte{ + 43, 213, 24, 193, 61, 16, 199, 94, 120, 255, 42, 44, 48, 36, 196, 250, 207, 25, 199, 203, 87, + 156, 26, 146, 232, 171, 179, 215, 12, 71, 124, 129, + }, 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}, + 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, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 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, 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}, + transactionBytes: []byte{ + 2, 0, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 44, 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, 44, 0, 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{ - ID: -7331232839985814584, - Version: 1, - TransactionType: 2, - BlockID: 0, - Height: 0, - Timestamp: 1562806389280, - SenderAccountType: 0, - SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", - RecipientAccountType: 0, - RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", - Fee: 1000000, - TransactionHash: []byte{200, 163, 247, 22, 147, 58, 66, 154, 228, 12, 17, 150, 30, 208, 23, 106, 153, 189, - 14, 184, 2, 76, 78, 23, 22, 114, 225, 61, 134, 142, 148, 186}, + ID: 3602917061812791438, + Version: 1, + TransactionType: 2, + BlockID: 0, + Height: 0, + Timestamp: 1562806389280, + SenderAccountAddressLength: uint32(len([]byte("BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7"))), + SenderAccountAddress: "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7", + RecipientAccountAddressLength: uint32(len([]byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"))), + RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", + Fee: 1000000, + TransactionHash: []byte{ + 142, 168, 139, 136, 250, 33, 0, 50, 23, 64, 67, 232, 186, 253, 134, 19, 59, 149, 71, 238, 156, 123, 77, + 203, 244, 160, 81, 179, 35, 24, 5, 81, + }, TransactionBodyLength: 8, TransactionBodyBytes: []byte{1, 2, 3, 4, 5, 6, 7, 8}, }, @@ -238,11 +250,11 @@ func TestParseTransactionBytes(t *testing.T) { { name: "ParseTransactionBytes:fail", args: args{ - 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}, + transactionBytes: []byte{2, 0, 0, 0, 1, 32, 10, 133, 222, 107, 1, 0, 0, 44, 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, 0, 0, 64, 66, 15, 0, 0, 0, 0, 0, 8, 0, 0, 0, 1, 2, 3, 4, 5, + 6, 7, 8}, sign: true, }, want: nil, @@ -375,22 +387,22 @@ func TestValidateTransaction(t *testing.T) { func buildTransaction(timestamp int64, sender, recipient string) *model.Transaction { return &model.Transaction{ - Version: 1, - ID: 2774809487, - BlockID: 1, - Height: 1, - SenderAccountType: 0, - SenderAccountAddress: sender, - RecipientAccountType: 0, - RecipientAccountAddress: recipient, - TransactionType: 0, - Fee: 1, - Timestamp: timestamp, - TransactionHash: make([]byte, 32), - TransactionBodyLength: 0, - TransactionBodyBytes: make([]byte, 0), - TransactionBody: nil, - Signature: make([]byte, 64), + Version: 1, + ID: 2774809487, + BlockID: 1, + Height: 1, + SenderAccountAddressLength: uint32(len([]byte(sender))), + SenderAccountAddress: sender, + RecipientAccountAddressLength: uint32(len([]byte(recipient))), + RecipientAccountAddress: recipient, + TransactionType: 0, + Fee: 1, + Timestamp: timestamp, + TransactionHash: make([]byte, 32), + TransactionBodyLength: 0, + TransactionBodyBytes: make([]byte, 0), + TransactionBody: nil, + Signature: make([]byte, 64), } } From 232453c63e8163ba91638164e9a9c5537fb9088a Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 15:35:34 +0800 Subject: [PATCH 12/27] #134 blocksmith address length remove --- common/model/block.pb.go | 111 ++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 60 deletions(-) diff --git a/common/model/block.pb.go b/common/model/block.pb.go index f45278c57..4da4cd271 100644 --- a/common/model/block.pb.go +++ b/common/model/block.pb.go @@ -22,26 +22,25 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Block represent the block data structure stored in the database type Block struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - PreviousBlockHash []byte `protobuf:"bytes,2,opt,name=PreviousBlockHash,proto3" json:"PreviousBlockHash,omitempty"` - Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` - Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` - BlockSeed []byte `protobuf:"bytes,5,opt,name=BlockSeed,proto3" json:"BlockSeed,omitempty"` - BlockSignature []byte `protobuf:"bytes,6,opt,name=BlockSignature,proto3" json:"BlockSignature,omitempty"` - CumulativeDifficulty string `protobuf:"bytes,7,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` - SmithScale int64 `protobuf:"varint,8,opt,name=SmithScale,proto3" json:"SmithScale,omitempty"` - BlocksmithAddressLength uint32 `protobuf:"varint,9,opt,name=BlocksmithAddressLength,proto3" json:"BlocksmithAddressLength,omitempty"` - BlocksmithAddress string `protobuf:"bytes,10,opt,name=BlocksmithAddress,proto3" json:"BlocksmithAddress,omitempty"` - TotalAmount int64 `protobuf:"varint,11,opt,name=TotalAmount,proto3" json:"TotalAmount,omitempty"` - TotalFee int64 `protobuf:"varint,12,opt,name=TotalFee,proto3" json:"TotalFee,omitempty"` - TotalCoinBase int64 `protobuf:"varint,13,opt,name=TotalCoinBase,proto3" json:"TotalCoinBase,omitempty"` - Version uint32 `protobuf:"varint,14,opt,name=Version,proto3" json:"Version,omitempty"` - PayloadLength uint32 `protobuf:"varint,15,opt,name=PayloadLength,proto3" json:"PayloadLength,omitempty"` - PayloadHash []byte `protobuf:"bytes,16,opt,name=PayloadHash,proto3" json:"PayloadHash,omitempty"` - Transactions []*Transaction `protobuf:"bytes,17,rep,name=Transactions,proto3" json:"Transactions,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` + PreviousBlockHash []byte `protobuf:"bytes,2,opt,name=PreviousBlockHash,proto3" json:"PreviousBlockHash,omitempty"` + Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` + Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` + BlockSeed []byte `protobuf:"bytes,5,opt,name=BlockSeed,proto3" json:"BlockSeed,omitempty"` + BlockSignature []byte `protobuf:"bytes,6,opt,name=BlockSignature,proto3" json:"BlockSignature,omitempty"` + CumulativeDifficulty string `protobuf:"bytes,7,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` + SmithScale int64 `protobuf:"varint,8,opt,name=SmithScale,proto3" json:"SmithScale,omitempty"` + BlocksmithAddress string `protobuf:"bytes,9,opt,name=BlocksmithAddress,proto3" json:"BlocksmithAddress,omitempty"` + TotalAmount int64 `protobuf:"varint,10,opt,name=TotalAmount,proto3" json:"TotalAmount,omitempty"` + TotalFee int64 `protobuf:"varint,11,opt,name=TotalFee,proto3" json:"TotalFee,omitempty"` + TotalCoinBase int64 `protobuf:"varint,12,opt,name=TotalCoinBase,proto3" json:"TotalCoinBase,omitempty"` + Version uint32 `protobuf:"varint,13,opt,name=Version,proto3" json:"Version,omitempty"` + PayloadLength uint32 `protobuf:"varint,14,opt,name=PayloadLength,proto3" json:"PayloadLength,omitempty"` + PayloadHash []byte `protobuf:"bytes,15,opt,name=PayloadHash,proto3" json:"PayloadHash,omitempty"` + Transactions []*Transaction `protobuf:"bytes,16,rep,name=Transactions,proto3" json:"Transactions,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Block) Reset() { *m = Block{} } @@ -125,13 +124,6 @@ func (m *Block) GetSmithScale() int64 { return 0 } -func (m *Block) GetBlocksmithAddressLength() uint32 { - if m != nil { - return m.BlocksmithAddressLength - } - return 0 -} - func (m *Block) GetBlocksmithAddress() string { if m != nil { return m.BlocksmithAddress @@ -383,37 +375,36 @@ func init() { func init() { proto.RegisterFile("model/block.proto", fileDescriptor_baa78346dbb08dbe) } var fileDescriptor_baa78346dbb08dbe = []byte{ - // 508 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xdf, 0x6b, 0x1a, 0x41, - 0x10, 0xe6, 0x8c, 0x9a, 0x38, 0xfe, 0x48, 0x5c, 0x42, 0xb3, 0x84, 0x52, 0x0e, 0x09, 0xe5, 0x28, - 0xad, 0x42, 0x0a, 0xa5, 0xaf, 0x51, 0x69, 0x13, 0xc8, 0x43, 0x38, 0xa5, 0x85, 0x3e, 0x14, 0xd6, - 0x73, 0xe2, 0x2d, 0xbd, 0xdd, 0xb5, 0xb7, 0x7b, 0x01, 0xfb, 0xde, 0xbf, 0xba, 0x2f, 0xe5, 0xe6, - 0x2e, 0x51, 0x6b, 0xa5, 0x7d, 0x11, 0xbf, 0xef, 0x9b, 0xfb, 0x66, 0x76, 0xf6, 0x5b, 0xe8, 0x2a, - 0x33, 0xc7, 0x64, 0x30, 0x4b, 0x4c, 0xf4, 0xad, 0xbf, 0x4c, 0x8d, 0x33, 0xac, 0x46, 0xd4, 0xf9, - 0x59, 0xa1, 0xb8, 0x54, 0x68, 0x2b, 0x22, 0x27, 0x8d, 0x2e, 0xf4, 0xde, 0xaf, 0x2a, 0xd4, 0x86, - 0x79, 0x3d, 0xeb, 0x40, 0xe5, 0x66, 0xcc, 0x3d, 0xdf, 0x0b, 0x0e, 0xc2, 0xca, 0xcd, 0x98, 0xbd, - 0x86, 0xee, 0x5d, 0x8a, 0x0f, 0xd2, 0x64, 0x96, 0x0a, 0xae, 0x85, 0x8d, 0x79, 0xc5, 0xf7, 0x82, - 0x56, 0xb8, 0x2b, 0xb0, 0x67, 0x50, 0xbf, 0x46, 0xb9, 0x88, 0x1d, 0x3f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32, 0x9f, 0xb1, 0x24, 0x28, 0x03, 0x27, 0x74, 0x09, 0x9b, 0x14, 0x7b, 0x07, 0xad, - 0xe9, 0x3a, 0x5a, 0x96, 0x77, 0xfd, 0x83, 0xa0, 0x79, 0xc9, 0xfa, 0x94, 0xba, 0xfe, 0x86, 0x14, - 0x6e, 0xd5, 0xf5, 0x3e, 0xc3, 0xf1, 0x47, 0x74, 0xb4, 0x95, 0x10, 0xbf, 0x67, 0x68, 0x29, 0x30, - 0xa3, 0x58, 0x48, 0x3d, 0x5d, 0x2d, 0x91, 0xd2, 0x58, 0x0b, 0xd7, 0x44, 0x19, 0xd2, 0xca, 0x53, - 0x48, 0xf7, 0xc4, 0xae, 0xf7, 0x15, 0x4e, 0x1e, 0x8d, 0xed, 0xff, 0x39, 0x9f, 0x42, 0xed, 0x56, - 0x2a, 0xe9, 0xc8, 0xbc, 0x1d, 0x16, 0x60, 0xaf, 0xff, 0x4f, 0x0f, 0xba, 0x1b, 0x0d, 0xec, 0xd2, - 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa2, 0x4b, 0x2e, 0x3b, 0x10, 0xd8, 0xfb, 0x70, 0x2e, 0xa0, 0x4e, - 0xef, 0xd8, 0xf2, 0x2a, 0x2d, 0xb3, 0x55, 0x2e, 0xb3, 0x58, 0x56, 0xa9, 0x0d, 0x5f, 0x7d, 0x09, - 0x16, 0xd2, 0xc5, 0xd9, 0xac, 0x1f, 0x19, 0x35, 0xf8, 0x61, 0xcc, 0x2c, 0x2a, 0x7e, 0xdf, 0x44, - 0x26, 0xc5, 0x41, 0x64, 0x94, 0x32, 0x7a, 0x40, 0x5f, 0xce, 0xea, 0xf4, 0xe2, 0xdf, 0xfe, 0x0e, - 0x00, 0x00, 0xff, 0xff, 0x7c, 0x21, 0x8e, 0x1d, 0x26, 0x04, 0x00, 0x00, + // 496 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x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0x7a, 0xbe, 0x59, 0x23, 0x65, 0xaa, 0x11, 0x6e, 0x89, + 0x32, 0x6a, 0xb5, 0xc7, 0xa8, 0xed, 0x09, 0xcf, 0xe0, 0x2b, 0x9c, 0x3c, 0x18, 0xdb, 0xff, 0x73, + 0x3e, 0x85, 0xc6, 0x8d, 0x54, 0xd2, 0x91, 0x79, 0x37, 0x2c, 0xc0, 0x5e, 0xff, 0x9f, 0x1e, 0xf4, + 0x2b, 0x0d, 0xec, 0xda, 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa1, 0x25, 0x97, 0x1d, 0x08, 0xec, 0x8d, + 0xff, 0x39, 0x34, 0xe9, 0x35, 0x5a, 0x5e, 0xa7, 0x61, 0x76, 0xca, 0x61, 0x16, 0xc3, 0x2a, 0xb5, + 0xf1, 0xeb, 0x2f, 0xc1, 0x4a, 0xba, 0x38, 0x5b, 0x0c, 0x23, 0xa3, 0x46, 0x3f, 0x8c, 0x59, 0x44, + 0xc5, 0xef, 0xdb, 0xc8, 0xa4, 0x38, 0x8a, 0x8c, 0x52, 0x46, 0x8f, 0xe8, 0xe4, 0xa2, 0x49, 0xef, + 0xf6, 0xdd, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9d, 0x78, 0x03, 0x78, 0xec, 0x03, 0x00, 0x00, } From d24918c15c288e6ef9bc508ba01a6527f8b84e9d Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 15:38:34 +0800 Subject: [PATCH 13/27] zoobc/zoobc-core#134 blocksmith address length revert --- common/model/block.pb.go | 111 +++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 51 deletions(-) diff --git a/common/model/block.pb.go b/common/model/block.pb.go index 4da4cd271..f45278c57 100644 --- a/common/model/block.pb.go +++ b/common/model/block.pb.go @@ -22,25 +22,26 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Block represent the block data structure stored in the database type Block struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - PreviousBlockHash []byte `protobuf:"bytes,2,opt,name=PreviousBlockHash,proto3" json:"PreviousBlockHash,omitempty"` - Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` - Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` - BlockSeed []byte `protobuf:"bytes,5,opt,name=BlockSeed,proto3" json:"BlockSeed,omitempty"` - BlockSignature []byte `protobuf:"bytes,6,opt,name=BlockSignature,proto3" json:"BlockSignature,omitempty"` - CumulativeDifficulty string `protobuf:"bytes,7,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` - SmithScale int64 `protobuf:"varint,8,opt,name=SmithScale,proto3" json:"SmithScale,omitempty"` - BlocksmithAddress string `protobuf:"bytes,9,opt,name=BlocksmithAddress,proto3" json:"BlocksmithAddress,omitempty"` - TotalAmount int64 `protobuf:"varint,10,opt,name=TotalAmount,proto3" json:"TotalAmount,omitempty"` - TotalFee int64 `protobuf:"varint,11,opt,name=TotalFee,proto3" json:"TotalFee,omitempty"` - TotalCoinBase int64 `protobuf:"varint,12,opt,name=TotalCoinBase,proto3" json:"TotalCoinBase,omitempty"` - Version uint32 `protobuf:"varint,13,opt,name=Version,proto3" json:"Version,omitempty"` - PayloadLength uint32 `protobuf:"varint,14,opt,name=PayloadLength,proto3" json:"PayloadLength,omitempty"` - PayloadHash []byte `protobuf:"bytes,15,opt,name=PayloadHash,proto3" json:"PayloadHash,omitempty"` - Transactions []*Transaction `protobuf:"bytes,16,rep,name=Transactions,proto3" json:"Transactions,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` + PreviousBlockHash []byte `protobuf:"bytes,2,opt,name=PreviousBlockHash,proto3" json:"PreviousBlockHash,omitempty"` + Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` + Timestamp int64 `protobuf:"varint,4,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` + BlockSeed []byte `protobuf:"bytes,5,opt,name=BlockSeed,proto3" json:"BlockSeed,omitempty"` + BlockSignature []byte `protobuf:"bytes,6,opt,name=BlockSignature,proto3" json:"BlockSignature,omitempty"` + CumulativeDifficulty string `protobuf:"bytes,7,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` + SmithScale int64 `protobuf:"varint,8,opt,name=SmithScale,proto3" json:"SmithScale,omitempty"` + BlocksmithAddressLength uint32 `protobuf:"varint,9,opt,name=BlocksmithAddressLength,proto3" json:"BlocksmithAddressLength,omitempty"` + BlocksmithAddress string `protobuf:"bytes,10,opt,name=BlocksmithAddress,proto3" json:"BlocksmithAddress,omitempty"` + TotalAmount int64 `protobuf:"varint,11,opt,name=TotalAmount,proto3" json:"TotalAmount,omitempty"` + TotalFee int64 `protobuf:"varint,12,opt,name=TotalFee,proto3" json:"TotalFee,omitempty"` + TotalCoinBase int64 `protobuf:"varint,13,opt,name=TotalCoinBase,proto3" json:"TotalCoinBase,omitempty"` + Version uint32 `protobuf:"varint,14,opt,name=Version,proto3" json:"Version,omitempty"` + PayloadLength uint32 `protobuf:"varint,15,opt,name=PayloadLength,proto3" json:"PayloadLength,omitempty"` + PayloadHash []byte `protobuf:"bytes,16,opt,name=PayloadHash,proto3" json:"PayloadHash,omitempty"` + Transactions []*Transaction `protobuf:"bytes,17,rep,name=Transactions,proto3" json:"Transactions,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Block) Reset() { *m = Block{} } @@ -124,6 +125,13 @@ func (m *Block) GetSmithScale() int64 { return 0 } +func (m *Block) GetBlocksmithAddressLength() uint32 { + if m != nil { + return m.BlocksmithAddressLength + } + return 0 +} + func (m *Block) GetBlocksmithAddress() string { if m != nil { return m.BlocksmithAddress @@ -375,36 +383,37 @@ func init() { func init() { proto.RegisterFile("model/block.proto", fileDescriptor_baa78346dbb08dbe) } var fileDescriptor_baa78346dbb08dbe = []byte{ - // 496 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x5d, 0x6b, 0x13, 0x41, - 0x14, 0x65, 0xd3, 0x24, 0x6d, 0x6e, 0x3e, 0xda, 0x0c, 0x45, 0x87, 0x22, 0xb2, 0x84, 0x22, 0x8b, - 0x68, 0x02, 0x15, 0x7c, 0x6f, 0x12, 0xb4, 0x85, 0x3e, 0x94, 0x4d, 0x50, 0xf0, 0x41, 0x98, 0x6c, - 0x6e, 0xb3, 0x83, 0x3b, 0x33, 0x71, 0x67, 0xb6, 0x10, 0xdf, 0xfd, 0x61, 0xfe, 0x33, 0xd9, 0xbb, - 0xdb, 0x66, 0x63, 0x0d, 0xfa, 0x12, 0x72, 0xce, 0xb9, 0x73, 0xee, 0xec, 0xbd, 0x67, 0xa0, 0xaf, - 0xcc, 0x12, 0x93, 0xd1, 0x22, 0x31, 0xd1, 0xb7, 0xe1, 0x3a, 0x35, 0xce, 0xb0, 0x06, 0x51, 0x67, - 0xcf, 0x0b, 0xc5, 0xa5, 0x42, 0x5b, 0x11, 0x39, 0x69, 0x74, 0xa1, 0x0f, 0x7e, 0xd5, 0xa1, 0x31, - 0xce, 0xeb, 0x59, 0x0f, 0x6a, 0xd7, 0x53, 0xee, 0xf9, 0x5e, 0x70, 0x10, 0xd6, 0xae, 0xa7, 0xec, - 0x0d, 0xf4, 0x6f, 0x53, 0xbc, 0x97, 0x26, 0xb3, 0x54, 0x70, 0x25, 0x6c, 0xcc, 0x6b, 0xbe, 0x17, - 0x74, 0xc2, 0xa7, 0x02, 0x7b, 0x06, 0xcd, 0x2b, 0x94, 0xab, 0xd8, 0xf1, 0x03, 0xdf, 0x0b, 0xba, - 0x61, 0x89, 0xd8, 0x0b, 0x68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, 0x0f, 0x82, 0xf6, 0x05, 0x1b, 0x52, - 0x76, 0x86, 0x15, 0x29, 0xdc, 0xa9, 0x1b, 0x7c, 0x86, 0xe3, 0x8f, 0xe8, 0x68, 0x2a, 0x21, 0x7e, - 0xcf, 0xd0, 0xd2, 0xda, 0x27, 0xb1, 0x90, 0x7a, 0xbe, 0x59, 0x23, 0x65, 0xaa, 0x11, 0x6e, 0x89, - 0x32, 0x6a, 0xb5, 0xc7, 0xa8, 0xed, 0x09, 0xcf, 0xe0, 0x2b, 0x9c, 0x3c, 0x18, 0xdb, 0xff, 0x73, - 0x3e, 0x85, 0xc6, 0x8d, 0x54, 0xd2, 0x91, 0x79, 0x37, 0x2c, 0xc0, 0x5e, 0xff, 0x9f, 0x1e, 0xf4, - 0x2b, 0x0d, 0xec, 0xda, 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa1, 0x25, 0x97, 0x1d, 0x08, 0xec, 0x8d, - 0xff, 0x39, 0x34, 0xe9, 0x35, 0x5a, 0x5e, 0xa7, 0x61, 0x76, 0xca, 0x61, 0x16, 0xc3, 0x2a, 0xb5, - 0xf1, 0xeb, 0x2f, 0xc1, 0x4a, 0xba, 0x38, 0x5b, 0x0c, 0x23, 0xa3, 0x46, 0x3f, 0x8c, 0x59, 0x44, - 0xc5, 0xef, 0xdb, 0xc8, 0xa4, 0x38, 0x8a, 0x8c, 0x52, 0x46, 0x8f, 0xe8, 0xe4, 0xa2, 0x49, 0xef, - 0xf6, 0xdd, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9d, 0x78, 0x03, 0x78, 0xec, 0x03, 0x00, 0x00, + // 508 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xdf, 0x6b, 0x1a, 0x41, + 0x10, 0xe6, 0x8c, 0x9a, 0x38, 0xfe, 0x48, 0x5c, 0x42, 0xb3, 0x84, 0x52, 0x0e, 0x09,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, 0xb1, 0xbc, 0xbf, 0x97, 0x51, 0x96, 0xb8, 0x15, 0x3f, 0xf4, 0xbd, 0xa0, 0x11, + 0xfe, 0x55, 0x63, 0x2f, 0x00, 0x26, 0x4a, 0xba, 0x78, 0x12, 0x89, 0x04, 0xf9, 0x11, 0x0d, 0xb6, + 0xc1, 0xb0, 0xf7, 0x70, 0x46, 0x5d, 0x6c, 0x4e, 0x5d, 0xcd, 0xe7, 0x29, 0x5a, 0x7b, 0x8b, 0x7a, + 0xe1, 0x62, 0xde, 0xa0, 0x03, 0xee, 0x93, 0xf3, 0xbd, 0xed, 0x48, 0x1c, 0x68, 0x94, 0x5d, 0x81, + 0xf9, 0xd0, 0x9c, 0x1a, 0x27, 0x92, 0x2b, 0x65, 0x32, 0xed, 0x78, 0x93, 0x06, 0xd9, 0xa4, 0xd8, + 0x39, 0x1c, 0x11, 0xfc, 0x80, 0xc8, 0x5b, 0x24, 0x3f, 0x61, 0x76, 0x01, 0x6d, 0xfa, 0x3f, 0x32, + 0x52, 0x0f, 0x85, 0x45, 0xde, 0xa6, 0x82, 0x6d, 0x92, 0x71, 0x38, 0xfc, 0x84, 0xa9, 0x95, 0x46, + 0xf3, 0x0e, 0xcd, 0xfe, 0x08, 0xf3, 0xef, 0xef, 0xc4, 0x2a, 0x31, 0x62, 0x5e, 0x9e, 0xed, 0x98, + 0xf4, 0x6d, 0x32, 0x9f, 0xb1, 0x24, 0x28, 0x03, 0x27, 0x74, 0x09, 0x9b, 0x14, 0x7b, 0x07, 0xad, + 0xe9, 0x3a, 0x5a, 0x96, 0x77, 0xfd, 0x83, 0xa0, 0x79, 0xc9, 0xfa, 0x94, 0xba, 0xfe, 0x86, 0x14, + 0x6e, 0xd5, 0xf5, 0x3e, 0xc3, 0xf1, 0x47, 0x74, 0xb4, 0x95, 0x10, 0xbf, 0x67, 0x68, 0x29, 0x30, + 0xa3, 0x58, 0x48, 0x3d, 0x5d, 0x2d, 0x91, 0xd2, 0x58, 0x0b, 0xd7, 0x44, 0x19, 0xd2, 0xca, 0x53, + 0x48, 0xf7, 0xc4, 0xae, 0xf7, 0x15, 0x4e, 0x1e, 0x8d, 0xed, 0xff, 0x39, 0x9f, 0x42, 0xed, 0x56, + 0x2a, 0xe9, 0xc8, 0xbc, 0x1d, 0x16, 0x60, 0xaf, 0xff, 0x4f, 0x0f, 0xba, 0x1b, 0x0d, 0xec, 0xd2, + 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa2, 0x4b, 0x2e, 0x3b, 0x10, 0xd8, 0xfb, 0x70, 0x2e, 0xa0, 0x4e, + 0xef, 0xd8, 0xf2, 0x2a, 0x2d, 0xb3, 0x55, 0x2e, 0xb3, 0x58, 0x56, 0xa9, 0x0d, 0x5f, 0x7d, 0x09, + 0x16, 0xd2, 0xc5, 0xd9, 0xac, 0x1f, 0x19, 0x35, 0xf8, 0x61, 0xcc, 0x2c, 0x2a, 0x7e, 0xdf, 0x44, + 0x26, 0xc5, 0x41, 0x64, 0x94, 0x32, 0x7a, 0x40, 0x5f, 0xce, 0xea, 0xf4, 0xe2, 0xdf, 0xfe, 0x0e, + 0x00, 0x00, 0xff, 0xff, 0x7c, 0x21, 0x8e, 0x1d, 0x26, 0x04, 0x00, 0x00, } From 284ce6cf99d3cbf8495fc22c816f58441c252fb6 Mon Sep 17 00:00:00 2001 From: astaphobia Date: Fri, 9 Aug 2019 16:07:56 +0800 Subject: [PATCH 14/27] fixed test cases --- api/service/blockApiService_test.go | 96 +++++++++++------------ api/service/transactionApiService_test.go | 47 ++++++----- 2 files changed, 74 insertions(+), 69 deletions(-) diff --git a/api/service/blockApiService_test.go b/api/service/blockApiService_test.go index c2d97e49e..2721f93a8 100644 --- a/api/service/blockApiService_test.go +++ b/api/service/blockApiService_test.go @@ -120,7 +120,6 @@ func (*mockQueryGetBlockByIDSuccess) ExecuteSelect(qStr string, args ...interfac 1, 1, []byte{4}, - 1, "smithAddress", 1, 1, @@ -156,22 +155,21 @@ func TestBlockService_GetBlockByID(t *testing.T) { }, wantErr: false, want: &model.Block{ - ID: 1, - PreviousBlockHash: []byte{1}, - Height: 1, - Timestamp: 10000, - BlockSeed: []byte{2}, - BlockSignature: []byte{3}, - CumulativeDifficulty: "cumulative", - SmithScale: 1, - BlocksmithAddressLength: 1, - BlocksmithAddress: "smithAddress", - PayloadLength: 1, - PayloadHash: []byte{4}, - TotalAmount: 1, - TotalFee: 1, - TotalCoinBase: 1, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{1}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{2}, + BlockSignature: []byte{3}, + CumulativeDifficulty: "cumulative", + SmithScale: 1, + BlocksmithAddress: "smithAddress", + PayloadLength: 1, + PayloadHash: []byte{4}, + TotalAmount: 1, + TotalFee: 1, + TotalCoinBase: 1, + Version: 1, }, }, { @@ -240,7 +238,6 @@ func (*mockQueryGetBlockByHeightSuccess) ExecuteSelect(qStr string, args ...inte 1, 1, []byte{4}, - 1, "smithAddress", 1, 1, @@ -277,22 +274,21 @@ func TestBlockService_GetBlockByHeight(t *testing.T) { }, wantErr: false, want: &model.Block{ - ID: 1, - PreviousBlockHash: []byte{1}, - Height: 1, - Timestamp: 10000, - BlockSeed: []byte{2}, - BlockSignature: []byte{3}, - CumulativeDifficulty: "cumulative", - SmithScale: 1, - BlocksmithAddressLength: 1, - BlocksmithAddress: "smithAddress", - PayloadLength: 1, - PayloadHash: []byte{4}, - TotalAmount: 1, - TotalFee: 1, - TotalCoinBase: 1, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{1}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{2}, + BlockSignature: []byte{3}, + CumulativeDifficulty: "cumulative", + SmithScale: 1, + BlocksmithAddress: "smithAddress", + PayloadLength: 1, + PayloadHash: []byte{4}, + TotalAmount: 1, + TotalFee: 1, + TotalCoinBase: 1, + Version: 1, }, }, { @@ -361,7 +357,6 @@ func (*mockQueryGetBlocksSuccess) ExecuteSelect(qStr string, args ...interface{} 1, 1, []byte{4}, - 1, "smithAddress", 1, 1, @@ -403,22 +398,21 @@ func TestBlockService_GetBlocks(t *testing.T) { Count: 1, Blocks: []*model.Block{ { - ID: 1, - PreviousBlockHash: []byte{1}, - Height: 1, - Timestamp: 10000, - BlockSeed: []byte{2}, - BlockSignature: []byte{3}, - CumulativeDifficulty: "cumulative", - SmithScale: 1, - BlocksmithAddressLength: 1, - BlocksmithAddress: "smithAddress", - PayloadLength: 1, - PayloadHash: []byte{4}, - TotalAmount: 1, - TotalFee: 1, - TotalCoinBase: 1, - Version: 1, + ID: 1, + PreviousBlockHash: []byte{1}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{2}, + BlockSignature: []byte{3}, + CumulativeDifficulty: "cumulative", + SmithScale: 1, + BlocksmithAddress: "smithAddress", + PayloadLength: 1, + PayloadHash: []byte{4}, + TotalAmount: 1, + TotalFee: 1, + TotalCoinBase: 1, + Version: 1, }, }, }, diff --git a/api/service/transactionApiService_test.go b/api/service/transactionApiService_test.go index 923d065f9..ba910ece2 100644 --- a/api/service/transactionApiService_test.go +++ b/api/service/transactionApiService_test.go @@ -60,9 +60,7 @@ type ( mockGetTransactionExecutorTxNoRow struct { query.Executor } - mockGetTransactionExecutorTxSuccess struct { - query.Executor - } + mockTransactionExecutorFailBeginTx struct { query.Executor } @@ -145,19 +143,6 @@ func (*mockGetTransactionExecutorTxNoRow) ExecuteSelect(qe string, args ...inter return db.Query(qe) } -func (*mockGetTransactionExecutorTxSuccess) ExecuteSelect(qe string, args ...interface{}) (*sql.Rows, error) { - db, mock, _ := sqlmock.New() - defer db.Close() - mock.ExpectQuery(qe).WillReturnRows(sqlmock.NewRows([]string{ - "ID", "BlockID", "Height", "SenderAccountType", "SenderAccountAddress", "RecipientAccountType", "RecipientAccountAddress", - "TransactionType", "Fee", "Timestamp", "TransactionHash", "TransactionBodyLength", "TransactionBodyBytes", "Signature", - "Version", - }).AddRow(4545420970999433273, 1, 1, 0, "senderA", 0, "recipientA", 1, 1, 10000, []byte{1, 1}, 8, []byte{1, 2, 3, 4, 5, 6, 7, 8}, - []byte{0, 0, 0, 0, 0, 0, 0}, 1, - )) - return db.Query(qe) -} - func (*mockTransactionExecutorFailBeginTx) BeginTx() error { return errors.New("mockedError") } @@ -629,6 +614,32 @@ func TestTransactionService_GetTransactions(t *testing.T) { } } +type ( + mockQueryGetTransactionSuccess struct { + query.Executor + } +) + +func (*mockQueryGetTransactionSuccess) ExecuteSelect(qStr string, args ...interface{}) (*sql.Rows, error) { + db, mock, _ := sqlmock.New() + mock.ExpectQuery("").WillReturnRows( + sqlmock.NewRows(query.NewTransactionQuery(&chaintype.MainChain{}).Fields).AddRow( + 4545420970999433273, + 1, + 1, + "senderA", + "recipientA", + 1, + 1, + 10000, + []byte{1, 1}, + 8, + []byte{1, 2, 3, 4, 5, 6, 7, 8}, + []byte{0, 0, 0, 0, 0, 0, 0}, 1, + ), + ) + return db.Query("") +} func TestTransactionService_GetTransaction(t *testing.T) { type fields struct { Query query.ExecutorInterface @@ -678,7 +689,7 @@ func TestTransactionService_GetTransaction(t *testing.T) { { name: "GetTransaction:success", fields: fields{ - Query: &mockGetTransactionExecutorTxSuccess{}, + Query: &mockQueryGetTransactionSuccess{}, }, args: args{ chainType: &chaintype.MainChain{}, @@ -718,7 +729,7 @@ func TestTransactionService_GetTransaction(t *testing.T) { return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("TransactionService.GetTransaction() = %v, want %v", got, tt.want) + t.Errorf("TransactionService.GetTransaction() got = \n%v, want = \n%v", got, tt.want) } }) } From b6c2e7cda3b8cbe0d31897aa57556f2d236fcbb6 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 9 Aug 2019 16:11:37 +0800 Subject: [PATCH 15/27] #134 update query tests --- common/query/accountBalanceQuery_test.go | 54 +++++++++++----------- common/query/mempoolQuery_test.go | 16 +++---- common/query/nodeRegistrationQuery.go | 2 +- common/query/nodeRegistrationQuery_test.go | 28 +++++------ 4 files changed, 49 insertions(+), 51 deletions(-) diff --git a/common/query/accountBalanceQuery_test.go b/common/query/accountBalanceQuery_test.go index 8aef23aff..300e4753d 100644 --- a/common/query/accountBalanceQuery_test.go +++ b/common/query/accountBalanceQuery_test.go @@ -30,7 +30,7 @@ func TestNewAccountBalanceQuery(t *testing.T) { var mockAccountBalanceQuery = &AccountBalanceQuery{ Fields: []string{ - "account_id", + "account_address", "block_height", "spendable_balance", "balance", @@ -41,12 +41,12 @@ var mockAccountBalanceQuery = &AccountBalanceQuery{ } var causedFields = map[string]interface{}{ - "account_id": []byte{1}, - "block_height": uint32(1), + "account_address": "BCZ", + "block_height": uint32(1), } var mockAccountBalance = &model.AccountBalance{ - AccountID: []byte{1}, + AccountAddress: "BCZ", BlockHeight: 0, SpendableBalance: 0, Balance: 0, @@ -56,10 +56,10 @@ var mockAccountBalance = &model.AccountBalance{ func TestAccountBalanceQuery_GetAccountBalanceByAccountID(t *testing.T) { t.Run("GetAccountBalanceByAccountID", func(t *testing.T) { - res, arg := mockAccountBalanceQuery.GetAccountBalanceByAccountID([]byte{1}) - want := "SELECT account_id,block_height,spendable_balance,balance,pop_revenue,latest " + - "FROM account_balance WHERE account_id = ? AND latest = 1" - wantArg := []byte{1} + res, arg := mockAccountBalanceQuery.GetAccountBalanceByAccountAddress("BCZ") + want := "SELECT account_address,block_height,spendable_balance,balance,pop_revenue,latest " + + "FROM account_balance WHERE account_address = ? AND latest = 1" + wantArg := "BCZ" if res != want { t.Errorf("string not match:\nget: %s\nwant: %s", res, want) } @@ -75,18 +75,18 @@ func TestAccountBalanceQuery_AddAccountBalance(t *testing.T) { res := mockAccountBalanceQuery.AddAccountBalance(100, causedFields) var want [][]interface{} want = append(want, []interface{}{ - "INSERT INTO account_balance (account_id, block_height, spendable_balance, balance, pop_revenue, latest) SELECT ?, " + - "1, 0, 0, 0, 1 WHERE NOT EXISTS (SELECT account_id FROM account_balance WHERE account_id = ?)", - causedFields["account_id"], causedFields["account_id"], + "INSERT INTO account_balance (account_address, block_height, spendable_balance, balance, pop_revenue, latest) SELECT ?, " + + "1, 0, 0, 0, 1 WHERE NOT EXISTS (SELECT account_address FROM account_balance WHERE account_address = ?)", + causedFields["account_address"], causedFields["account_address"], }, []interface{}{ - "INSERT INTO account_balance (account_id, block_height, spendable_balance, balance, pop_revenue, latest) SELECT account_id, " + - "1, spendable_balance + 100, balance + 100, pop_revenue, latest FROM account_balance WHERE account_id = ? AND latest = 1 " + - "ON CONFLICT(account_id, block_height) DO UPDATE SET (spendable_balance, balance) = (SELECT spendable_balance + 100, balance " + - "+ 100 FROM account_balance WHERE account_id = ? AND latest = 1)", - causedFields["account_id"], causedFields["account_id"], + "INSERT INTO account_balance (account_address, block_height, spendable_balance, balance, pop_revenue, latest) SELECT account_address, " + + "1, spendable_balance + 100, balance + 100, pop_revenue, latest FROM account_balance WHERE account_address = ? AND latest = 1 " + + "ON CONFLICT(account_address, block_height) DO UPDATE SET (spendable_balance, balance) = (SELECT spendable_balance + 100, balance " + + "+ 100 FROM account_balance WHERE account_address = ? AND latest = 1)", + causedFields["account_address"], causedFields["account_address"], }, []interface{}{ - "UPDATE account_balance SET latest = false WHERE account_id = ? AND block_height != 1 AND latest = true", - causedFields["account_id"], + "UPDATE account_balance SET latest = false WHERE account_address = ? AND block_height != 1 AND latest = true", + causedFields["account_address"], }) if !reflect.DeepEqual(res, want) { t.Errorf("string not match:\nget: %s\nwant: %s", res, want) @@ -97,10 +97,8 @@ func TestAccountBalanceQuery_AddAccountBalance(t *testing.T) { func TestAccountBalanceQuery_AddAccountSpendableBalance(t *testing.T) { t.Run("AddAccountSpendableBalance:succes", func(t *testing.T) { q, args := mockAccountBalanceQuery.AddAccountSpendableBalance(100, causedFields) - wantQ := "UPDATE account_balance SET spendable_balance = spendable_balance + (100) WHERE account_id = ?" - wantArg := []interface{}{ - causedFields["account_id"], - } + wantQ := "UPDATE account_balance SET spendable_balance = spendable_balance + (100) WHERE account_address = ?" + wantArg := []interface{}{"BCZ"} if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) } @@ -115,9 +113,9 @@ func TestAccountBalanceQuery_InsertAccountBalance(t *testing.T) { t.Run("InsertAccountBalance:success", func(t *testing.T) { q, args := mockAccountBalanceQuery.InsertAccountBalance(mockAccountBalance) - wantQ := "INSERT INTO account_balance (account_id,block_height,spendable_balance,balance,pop_revenue,latest) VALUES(? , ?, ?, ?, ?, ?)" + wantQ := "INSERT INTO account_balance (account_address,block_height,spendable_balance,balance,pop_revenue,latest) VALUES(? , ?, ?, ?, ?, ?)" wantArg := []interface{}{ - mockAccountBalance.AccountID, mockAccountBalance.BlockHeight, mockAccountBalance.SpendableBalance, mockAccountBalance.Balance, + mockAccountBalance.AccountAddress, mockAccountBalance.BlockHeight, mockAccountBalance.SpendableBalance, mockAccountBalance.Balance, mockAccountBalance.PopRevenue, true, } if q != wantQ { @@ -133,7 +131,7 @@ func TestAccountBalanceQuery_ExtractModel(t *testing.T) { t.Run("ExtractModel:success", func(t *testing.T) { res := mockAccountBalanceQuery.ExtractModel(mockAccountBalance) want := []interface{}{ - mockAccountBalance.AccountID, mockAccountBalance.BlockHeight, mockAccountBalance.SpendableBalance, mockAccountBalance.Balance, + mockAccountBalance.AccountAddress, mockAccountBalance.BlockHeight, mockAccountBalance.SpendableBalance, mockAccountBalance.Balance, mockAccountBalance.PopRevenue, true, } if !reflect.DeepEqual(res, want) { @@ -147,14 +145,14 @@ func TestAccountBalanceQuery_BuildModel(t *testing.T) { db, mock, _ := sqlmock.New() defer db.Close() mock.ExpectQuery("foo").WillReturnRows(sqlmock.NewRows([]string{ - "AccountID", "BlockHeight", "SpendableBalance", "Balance", "PopRevenue", "Latest"}). - AddRow(mockAccountBalance.AccountID, mockAccountBalance.BlockHeight, mockAccountBalance.SpendableBalance, + "AccountAddress", "BlockHeight", "SpendableBalance", "Balance", "PopRevenue", "Latest"}). + AddRow(mockAccountBalance.AccountAddress, mockAccountBalance.BlockHeight, mockAccountBalance.SpendableBalance, mockAccountBalance.Balance, mockAccountBalance.PopRevenue, mockAccountBalance.Latest)) rows, _ := db.Query("foo") var tempAccount []*model.AccountBalance res := mockAccountBalanceQuery.BuildModel(tempAccount, rows) if !reflect.DeepEqual(res[0], mockAccountBalance) { - t.Errorf("arguments returned wrong: get: %v\nwant: %v", res, mockAccount) + t.Errorf("arguments returned wrong: get: %v\nwant: %v", res, mockAccountBalance) } }) } diff --git a/common/query/mempoolQuery_test.go b/common/query/mempoolQuery_test.go index 82d6cca22..87b266d0d 100644 --- a/common/query/mempoolQuery_test.go +++ b/common/query/mempoolQuery_test.go @@ -21,12 +21,12 @@ var mockMempoolQuery = &MempoolQuery{ } var mockMempool = &model.MempoolTransaction{ - ID: 1, - ArrivalTimestamp: 1000, - FeePerByte: 10, - TransactionBytes: []byte{1, 2, 3, 4, 5}, - SenderAccountID: []byte{1}, - RecipientAccountID: []byte{2}, + ID: 1, + ArrivalTimestamp: 1000, + FeePerByte: 10, + TransactionBytes: []byte{1, 2, 3, 4, 5}, + SenderAccountAddress: "BCZ", + RecipientAccountAddress: "ZCB", } func TestNewMempoolQuery(t *testing.T) { @@ -126,8 +126,8 @@ func TestMempoolQuery_ExtractModel(t *testing.T) { mockMempool.FeePerByte, mockMempool.ArrivalTimestamp, mockMempool.TransactionBytes, - mockMempool.SenderAccountID, - mockMempool.RecipientAccountID, + mockMempool.SenderAccountAddress, + mockMempool.RecipientAccountAddress, } if !reflect.DeepEqual(res, want) { t.Errorf("arguments returned wrong: get: %v\nwant: %v", res, want) diff --git a/common/query/nodeRegistrationQuery.go b/common/query/nodeRegistrationQuery.go index d1427a425..b8619b00e 100644 --- a/common/query/nodeRegistrationQuery.go +++ b/common/query/nodeRegistrationQuery.go @@ -81,7 +81,7 @@ func (nr *NodeRegistrationQuery) GetNodeRegistrationByNodePublicKey(nodePublicKe // GetNodeRegistrationByAccountID returns query string to get Node Registration by account public key func (nr *NodeRegistrationQuery) GetNodeRegistrationByAccountAddress(accountAddress string) (str string, args []interface{}) { - return fmt.Sprintf("SELECT %s FROM %s WHERE account_address = %d AND latest=1", + return fmt.Sprintf("SELECT %s FROM %s WHERE account_address = %s AND latest=1", strings.Join(nr.Fields, ", "), nr.getTableName(), accountAddress), []interface{}{accountAddress} } diff --git a/common/query/nodeRegistrationQuery_test.go b/common/query/nodeRegistrationQuery_test.go index 3986f8a41..244424e9f 100644 --- a/common/query/nodeRegistrationQuery_test.go +++ b/common/query/nodeRegistrationQuery_test.go @@ -9,7 +9,7 @@ import ( ) var mockNodeRegistrationQuery = &NodeRegistrationQuery{ - Fields: []string{"id", "node_public_key", "account_id", "registration_height", "node_address", "locked_balance", "queued", + Fields: []string{"id", "node_public_key", "account_address", "registration_height", "node_address", "locked_balance", "queued", "latest", "height"}, TableName: "node_registry", } @@ -17,7 +17,7 @@ var mockNodeRegistrationQuery = &NodeRegistrationQuery{ var mockNodeRegistry = &model.NodeRegistration{ NodeID: 1, NodePublicKey: []byte{1}, - AccountId: []byte{2}, + AccountAddress: "BCZ", RegistrationHeight: 1, NodeAddress: "127.0.0.1", LockedBalance: 10000, @@ -57,10 +57,10 @@ func TestNodeRegistrationQuery_InsertNodeRegistration(t *testing.T) { t.Run("InsertNodeRegistration:success", func(t *testing.T) { q, args := mockNodeRegistrationQuery.InsertNodeRegistration(mockNodeRegistry) - wantQ := "INSERT INTO node_registry (id,node_public_key,account_id,registration_height,node_address," + + wantQ := "INSERT INTO node_registry (id,node_public_key,account_address,registration_height,node_address," + "locked_balance,queued,latest,height) VALUES(? , ?, ?, ?, ?, ?, ?, ?, ?)" wantArg := []interface{}{ - mockNodeRegistry.NodeID, mockNodeRegistry.NodePublicKey, mockNodeRegistry.AccountId, mockNodeRegistry.RegistrationHeight, + mockNodeRegistry.NodeID, mockNodeRegistry.NodePublicKey, mockNodeRegistry.AccountAddress, mockNodeRegistry.RegistrationHeight, mockNodeRegistry.NodeAddress, mockNodeRegistry.LockedBalance, mockNodeRegistry.Queued, mockNodeRegistry.Latest, mockNodeRegistry.Height, } @@ -76,7 +76,7 @@ func TestNodeRegistrationQuery_InsertNodeRegistration(t *testing.T) { func TestNodeRegistrationQuery_GetNodeRegistrations(t *testing.T) { t.Run("GetNodeRegistrations", func(t *testing.T) { res := mockNodeRegistrationQuery.GetNodeRegistrations(0, 2) - want := "SELECT id, node_public_key, account_id, registration_height, node_address, locked_balance, " + + want := "SELECT id, node_public_key, account_address, registration_height, node_address, locked_balance, " + "queued, latest, height FROM node_registry WHERE height >= 0 AND latest=1 LIMIT 2" if res != want { t.Errorf("string not match:\nget: %s\nwant: %s", res, want) @@ -87,7 +87,7 @@ func TestNodeRegistrationQuery_GetNodeRegistrations(t *testing.T) { func TestNodeRegistrationQuery_GetNodeRegistrationByNodePublicKey(t *testing.T) { t.Run("GetNodeRegistrationByNodePublicKey:success", func(t *testing.T) { res, arg := mockNodeRegistrationQuery.GetNodeRegistrationByNodePublicKey([]byte{1}) - want := "SELECT id, node_public_key, account_id, registration_height, node_address, locked_balance, " + + want := "SELECT id, node_public_key, account_address, registration_height, node_address, locked_balance, " + "queued, latest, height FROM node_registry WHERE node_public_key = ? AND latest=1" wantArg := []interface{}{[]byte{1}} if res != want { @@ -101,10 +101,10 @@ func TestNodeRegistrationQuery_GetNodeRegistrationByNodePublicKey(t *testing.T) func TestNodeRegistrationQuery_GetNodeRegistrationByAccountPublicKey(t *testing.T) { t.Run("GetNodeRegistrationByNodePublicKey:success", func(t *testing.T) { - res, arg := mockNodeRegistrationQuery.GetNodeRegistrationByAccountID([]byte{1}) - want := "SELECT id, node_public_key, account_id, registration_height, node_address, locked_balance, " + + res, arg := mockNodeRegistrationQuery.GetNodeRegistrationByAccountAddress("BCZ") + want := "SELECT id, node_public_key, account_address, registration_height, node_address, locked_balance, " + "queued, latest, height FROM node_registry WHERE account_id = [1] AND latest=1" - wantArg := []interface{}{[]byte{1}} + wantArg := []interface{}{"BCZ"} if res != want { t.Errorf("string not match:\nget: %s\nwant: %s", res, want) } @@ -118,7 +118,7 @@ func TestNodeRegistrationQuery_ExtractModel(t *testing.T) { t.Run("NodeRegistration:ExtractModel:success", func(t *testing.T) { res := mockNodeRegistrationQuery.ExtractModel(mockNodeRegistry) want := []interface{}{ - mockNodeRegistry.NodeID, mockNodeRegistry.NodePublicKey, mockNodeRegistry.AccountId, mockNodeRegistry.RegistrationHeight, + mockNodeRegistry.NodeID, mockNodeRegistry.NodePublicKey, mockNodeRegistry.AccountAddress, mockNodeRegistry.RegistrationHeight, mockNodeRegistry.NodeAddress, mockNodeRegistry.LockedBalance, mockNodeRegistry.Queued, mockNodeRegistry.Latest, mockNodeRegistry.Height, } @@ -133,9 +133,9 @@ func TestNodeRegistrationQuery_BuildModel(t *testing.T) { db, mock, _ := sqlmock.New() defer db.Close() mock.ExpectQuery("foo").WillReturnRows(sqlmock.NewRows([]string{ - "id", "NodePublicKey", "AccountId", "RegistrationHeight", "NodeAddress", "LockedBalance", + "id", "NodePublicKey", "AccountAddress", "RegistrationHeight", "NodeAddress", "LockedBalance", "Queued", "Latest", "Height"}). - AddRow(mockNodeRegistry.NodeID, mockNodeRegistry.NodePublicKey, mockNodeRegistry.AccountId, mockNodeRegistry.RegistrationHeight, + AddRow(mockNodeRegistry.NodeID, mockNodeRegistry.NodePublicKey, mockNodeRegistry.AccountAddress, mockNodeRegistry.RegistrationHeight, mockNodeRegistry.NodeAddress, mockNodeRegistry.LockedBalance, mockNodeRegistry.Queued, mockNodeRegistry.Latest, mockNodeRegistry.Height)) rows, _ := db.Query("foo") @@ -152,10 +152,10 @@ func TestNodeRegistrationQuery_UpdateNodeRegistration(t *testing.T) { q, args := mockNodeRegistrationQuery.UpdateNodeRegistration(mockNodeRegistry) wantQ0 := "UPDATE node_registry SET latest = 0 WHERE ID = 1" - wantQ1 := "INSERT INTO node_registry (id,node_public_key,account_id,registration_height,node_address," + + wantQ1 := "INSERT INTO node_registry (id,node_public_key,account_address,registration_height,node_address," + "locked_balance,queued,latest,height) VALUES(? , ?, ?, ?, ?, ?, ?, ?, ?)" wantArg := []interface{}{ - mockNodeRegistry.NodeID, mockNodeRegistry.NodePublicKey, mockNodeRegistry.AccountId, mockNodeRegistry.RegistrationHeight, + mockNodeRegistry.NodeID, mockNodeRegistry.NodePublicKey, mockNodeRegistry.AccountAddress, mockNodeRegistry.RegistrationHeight, mockNodeRegistry.NodeAddress, mockNodeRegistry.LockedBalance, mockNodeRegistry.Queued, mockNodeRegistry.Latest, mockNodeRegistry.Height, } From 4086c60c5133fb50290fe0707ddd444911ab8109 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 09:46:30 +0800 Subject: [PATCH 16/27] #134 remove account type --- api/client/GetAccountBalance/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/api/client/GetAccountBalance/client.go b/api/client/GetAccountBalance/client.go index 45cb9fe26..3439a823b 100644 --- a/api/client/GetAccountBalance/client.go +++ b/api/client/GetAccountBalance/client.go @@ -19,7 +19,6 @@ func main() { c := rpc_service.NewAccountBalanceServiceClient(conn) response, err := c.GetAccountBalance(context.Background(), &rpc_model.GetAccountBalanceRequest{ - AccountType: 0, AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", }) From 77e66e22f3f9ce4c03dfc01a0b95ce2e74c42f53 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 09:47:04 +0800 Subject: [PATCH 17/27] #134 remove account type and add account address length --- common/transaction/fixtureGenerator.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/common/transaction/fixtureGenerator.go b/common/transaction/fixtureGenerator.go index a49124edd..ac05ca8b4 100644 --- a/common/transaction/fixtureGenerator.go +++ b/common/transaction/fixtureGenerator.go @@ -1,6 +1,7 @@ package transaction import ( + "fmt" "github.com/zoobc/zoobc-core/common/crypto" "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/common/util" @@ -12,7 +13,6 @@ func GetFixtures() (poownMessage *model.ProofOfOwnershipMessage, poown *model.Pr senderAddress := "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN" senderSeed := "prune filth cleaver removable earthworm tricky sulfur citation hesitate stout snort guy" poownMessage = &model.ProofOfOwnershipMessage{ - AccountType: 0, AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", BlockHash: []byte{0, 14, 6, 218, 170, 54, 60, 50, 2, 66, 130, 119, 226, 235, 126, 203, 5, 12, 152, 194, 170, 146, 43, 63, 224, 101, 127, 241, 62, 152, 187, 255, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, 80, 53, 116, 113, 70, 81, 108, 77, 84, 89, @@ -32,16 +32,18 @@ func GetFixtures() (poownMessage *model.ProofOfOwnershipMessage, poown *model.Pr txBody = &model.NodeRegistrationTransactionBody{ NodePublicKey: []byte{0, 14, 6, 218, 170, 54, 60, 50, 2, 66, 130, 119, 226, 235, 126, 203, 5, 12, 152, 194, 170, 146, 43, 63, 224, 101, 127, 241, 62, 152, 187, 255}, - AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", - RegistrationHeight: 0, - NodeAddressLength: 9, - NodeAddress: "10.10.0.1", - LockedBalance: 10000000000, - Poown: poown, + AccountAddressLength: uint32(len("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN")), + AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", + RegistrationHeight: 0, + NodeAddressLength: 9, + NodeAddress: "10.10.0.1", + LockedBalance: 10000000000, + Poown: poown, } nr := NodeRegistration{ Body: txBody, } txBodyBytes = nr.GetBodyBytes() + fmt.Printf("txBodyBytes: %v", txBodyBytes) return poownMessage, poown, txBody, txBodyBytes } From 8b628bdcf6f67fa259df8890ed7bbaec7d8bd335 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 09:47:54 +0800 Subject: [PATCH 18/27] #134 adjust query for account type deletion --- common/query/accountBalanceQuery.go | 5 +++-- common/query/accountBalanceQuery_test.go | 3 ++- common/query/blockQuery.go | 6 ++---- common/query/blockQuery_test.go | 22 ++++++++++---------- common/query/nodeRegistrationQuery_test.go | 4 ++-- common/query/transactionQuery_test.go | 24 +++++++++++----------- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/common/query/accountBalanceQuery.go b/common/query/accountBalanceQuery.go index c2086a0fa..280c7726c 100644 --- a/common/query/accountBalanceQuery.go +++ b/common/query/accountBalanceQuery.go @@ -55,8 +55,9 @@ func (q *AccountBalanceQuery) AddAccountBalance(balance int64, causedFields map[ causedFields["block_height"], q.TableName) // update or insert new account_balance row updateBalanceQuery := fmt.Sprintf("INSERT INTO %s (account_address, block_height, spendable_balance, balance, pop_revenue, latest) "+ - "SELECT account_address, %d, spendable_balance + %d, balance + %d, pop_revenue, latest FROM account_balance WHERE account_address = ? AND "+ - "latest = 1 ON CONFLICT(account_address, block_height) DO UPDATE SET (spendable_balance, balance) = (SELECT "+ + "SELECT account_address, %d, spendable_balance + %d, balance + %d, pop_revenue, latest FROM account_balance WHERE "+ + "account_address = ? AND latest = 1 ON CONFLICT(account_address, block_height) "+ + "DO UPDATE SET (spendable_balance, balance) = (SELECT "+ "spendable_balance + %d, balance + %d FROM %s WHERE account_address = ? AND latest = 1)", q.TableName, causedFields["block_height"], balance, balance, balance, balance, q.TableName) diff --git a/common/query/accountBalanceQuery_test.go b/common/query/accountBalanceQuery_test.go index 300e4753d..55f4bac8f 100644 --- a/common/query/accountBalanceQuery_test.go +++ b/common/query/accountBalanceQuery_test.go @@ -113,7 +113,8 @@ func TestAccountBalanceQuery_InsertAccountBalance(t *testing.T) { t.Run("InsertAccountBalance:success", func(t *testing.T) { q, args := mockAccountBalanceQuery.InsertAccountBalance(mockAccountBalance) - wantQ := "INSERT INTO account_balance (account_address,block_height,spendable_balance,balance,pop_revenue,latest) VALUES(? , ?, ?, ?, ?, ?)" + wantQ := "INSERT INTO account_balance (account_address,block_height,spendable_balance,balance,pop_revenue,latest) " + + "VALUES(? , ?, ?, ?, ?, ?)" wantArg := []interface{}{ mockAccountBalance.AccountAddress, mockAccountBalance.BlockHeight, mockAccountBalance.SpendableBalance, mockAccountBalance.Balance, mockAccountBalance.PopRevenue, true, diff --git a/common/query/blockQuery.go b/common/query/blockQuery.go index 986074163..379a23279 100644 --- a/common/query/blockQuery.go +++ b/common/query/blockQuery.go @@ -41,13 +41,13 @@ func NewBlockQuery(chaintype contract.ChainType) *BlockQuery { "block_signature", "cumulative_difficulty", "smith_scale", + "payload_length", + "payload_hash", "blocksmith_address", "total_amount", "total_fee", "total_coinbase", "version", - "payload_length", - "payload_hash", }, TableName: "block", ChainType: chaintype, @@ -106,8 +106,6 @@ func (*BlockQuery) ExtractModel(block *model.Block) []interface{} { block.TotalFee, block.TotalCoinBase, block.Version, - block.PayloadLength, - block.PayloadHash, } } diff --git a/common/query/blockQuery_test.go b/common/query/blockQuery_test.go index 21a4a04eb..a81cbb3f3 100644 --- a/common/query/blockQuery_test.go +++ b/common/query/blockQuery_test.go @@ -15,7 +15,7 @@ import ( var mockBlockQuery = &BlockQuery{ Fields: []string{"id", "previous_block_hash", "height", "timestamp", "block_seed", "block_signature", "cumulative_difficulty", - "smith_scale", "payload_length", "payload_hash", "blocksmith_id", "total_amount", "total_fee", "total_coinbase", "version", + "smith_scale", "payload_length", "payload_hash", "blocksmith_address", "total_amount", "total_fee", "total_coinbase", "version", }, TableName: "block", ChainType: &chaintype.MainChain{}, @@ -26,7 +26,7 @@ var mockBlock = &model.Block{ Height: 0, BlockSeed: []byte{1, 2, 3}, BlockSignature: []byte{1, 2, 3, 4, 5}, - BlocksmithID: []byte{0, 0, 0, 0, 0}, + BlocksmithAddress: "BCZ", CumulativeDifficulty: "0", PayloadHash: []byte{}, PayloadLength: 1, @@ -80,7 +80,7 @@ func TestBlockQuery_GetBlocks(t *testing.T) { t.Run("GetBlocks:success", func(t *testing.T) { q := mockBlockQuery.GetBlocks(0, 10) wantQ := "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height " + + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height " + ">= 0 LIMIT 10" if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) @@ -92,7 +92,7 @@ func TestBlockQuery_GetLastBlock(t *testing.T) { t.Run("GetLastBlock:success", func(t *testing.T) { q := mockBlockQuery.GetLastBlock() wantQ := "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block ORDER BY height " + + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block ORDER BY height " + "DESC LIMIT 1" if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) @@ -104,7 +104,7 @@ func TestBlockQuery_GetGenesisBlock(t *testing.T) { t.Run("GetGenesisBlock:success", func(t *testing.T) { q := mockBlockQuery.GetGenesisBlock() wantQ := "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height " + + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height " + "= 0 LIMIT 1" if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) @@ -116,7 +116,7 @@ func TestBlockQuery_InsertBlock(t *testing.T) { t.Run("InsertBlock:success", func(t *testing.T) { q, args := mockBlockQuery.InsertBlock(mockBlock) wantQ := "INSERT INTO main_block (id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, " + - "smith_scale, payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version) VALUES(? , ?, ?, ?, " + + "smith_scale, payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version) VALUES(? , ?, ?, ?, " + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" wantArg := mockBlockQuery.ExtractModel(mockBlock) @@ -133,7 +133,7 @@ func TestBlockQuery_GetBlockByID(t *testing.T) { t.Run("GetBlockByID:success", func(t *testing.T) { q := mockBlockQuery.GetBlockByID(1) wantQ := "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block WHERE id = 1" + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block WHERE id = 1" if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) } @@ -144,7 +144,7 @@ func TestBlockQuery_GetBlockByHeight(t *testing.T) { t.Run("GetBlockByHeight:success", func(t *testing.T) { q := mockBlockQuery.GetBlockByHeight(0) wantQ := "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + - "payload_length, payload_hash, blocksmith_id, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height = 0" + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block WHERE height = 0" if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) } @@ -165,7 +165,7 @@ func TestBlockQuery_ExtractModel(t *testing.T) { mockBlock.SmithScale, mockBlock.PayloadLength, mockBlock.PayloadHash, - mockBlock.BlocksmithID, + mockBlock.BlocksmithAddress, mockBlock.TotalAmount, mockBlock.TotalFee, mockBlock.TotalCoinBase, @@ -194,7 +194,7 @@ func TestBlockQuery_BuildModel(t *testing.T) { mockBlock.SmithScale, mockBlock.PayloadLength, mockBlock.PayloadHash, - mockBlock.BlocksmithID, + mockBlock.BlocksmithAddress, mockBlock.TotalAmount, mockBlock.TotalFee, mockBlock.TotalCoinBase, @@ -204,7 +204,7 @@ func TestBlockQuery_BuildModel(t *testing.T) { var tempBlock []*model.Block res := mockBlockQuery.BuildModel(tempBlock, rows) if !reflect.DeepEqual(res[0], mockBlock) { - t.Errorf("arguments returned wrong: get: %v\nwant: %v", res, mockAccount) + t.Errorf("arguments returned wrong: get: %v\nwant: %v", res, mockBlock) } }) } diff --git a/common/query/nodeRegistrationQuery_test.go b/common/query/nodeRegistrationQuery_test.go index 244424e9f..c108f78a0 100644 --- a/common/query/nodeRegistrationQuery_test.go +++ b/common/query/nodeRegistrationQuery_test.go @@ -103,7 +103,7 @@ func TestNodeRegistrationQuery_GetNodeRegistrationByAccountPublicKey(t *testing. t.Run("GetNodeRegistrationByNodePublicKey:success", func(t *testing.T) { res, arg := mockNodeRegistrationQuery.GetNodeRegistrationByAccountAddress("BCZ") want := "SELECT id, node_public_key, account_address, registration_height, node_address, locked_balance, " + - "queued, latest, height FROM node_registry WHERE account_id = [1] AND latest=1" + "queued, latest, height FROM node_registry WHERE account_address = BCZ AND latest=1" wantArg := []interface{}{"BCZ"} if res != want { t.Errorf("string not match:\nget: %s\nwant: %s", res, want) @@ -174,7 +174,7 @@ func TestNodeRegistrationQuery_UpdateNodeRegistration(t *testing.T) { func TestNodeRegistrationQuery_GetNodeRegistrationByID(t *testing.T) { t.Run("GetNodeRegistrationByID:success", func(t *testing.T) { res, arg := mockNodeRegistrationQuery.GetNodeRegistrationByID(1) - want := "SELECT id, node_public_key, account_id, registration_height, node_address, locked_balance," + + want := "SELECT id, node_public_key, account_address, registration_height, node_address, locked_balance," + " queued, latest, height FROM node_registry WHERE id = ? AND latest=1" wantArg := []interface{}{int64(1)} if res != want { diff --git a/common/query/transactionQuery_test.go b/common/query/transactionQuery_test.go index 43747ef7a..a550decc3 100644 --- a/common/query/transactionQuery_test.go +++ b/common/query/transactionQuery_test.go @@ -21,8 +21,8 @@ func TestGetTransaction(t *testing.T) { { name: "transaction query without condition", params: ¶msStruct{}, - want: "SELECT id, block_id, block_height, sender_account_type, sender_account_address, " + - "recipient_account_type, recipient_account_address, transaction_type, fee, timestamp, " + + want: "SELECT id, block_id, block_height, sender_account_address, " + + "recipient_account_address, transaction_type, fee, timestamp, " + "transaction_hash, transaction_body_length, transaction_body_bytes, signature, version from \"transaction\"", }, { @@ -30,8 +30,8 @@ func TestGetTransaction(t *testing.T) { params: ¶msStruct{ ID: 1, }, - want: "SELECT id, block_id, block_height, sender_account_type, sender_account_address, " + - "recipient_account_type, recipient_account_address, transaction_type, fee, timestamp, " + + want: "SELECT id, block_id, block_height, sender_account_address, " + + "recipient_account_address, transaction_type, fee, timestamp, " + "transaction_hash, transaction_body_length, transaction_body_bytes, signature, version from \"transaction\" " + "WHERE id = 1", }, @@ -63,8 +63,8 @@ func TestGetTransactions(t *testing.T) { { name: "transactions query without condition", params: ¶msStruct{}, - want: "SELECT id, block_id, block_height, sender_account_type, sender_account_address, " + - "recipient_account_type, recipient_account_address, transaction_type, fee, timestamp, " + + want: "SELECT id, block_id, block_height, sender_account_address, " + + "recipient_account_address, transaction_type, fee, timestamp, " + "transaction_hash, transaction_body_length, transaction_body_bytes, signature, version from " + "\"transaction\" ORDER BY block_height, timestamp LIMIT 0,10", }, @@ -73,8 +73,8 @@ func TestGetTransactions(t *testing.T) { params: ¶msStruct{ Limit: 10, }, - want: "SELECT id, block_id, block_height, sender_account_type, sender_account_address, " + - "recipient_account_type, recipient_account_address, transaction_type, fee, timestamp, " + + want: "SELECT id, block_id, block_height, sender_account_address, " + + "recipient_account_address, transaction_type, fee, timestamp, " + "transaction_hash, transaction_body_length, transaction_body_bytes, signature, version from " + "\"transaction\" ORDER BY block_height, timestamp LIMIT 0,10", }, @@ -83,8 +83,8 @@ func TestGetTransactions(t *testing.T) { params: ¶msStruct{ Offset: 20, }, - want: "SELECT id, block_id, block_height, sender_account_type, sender_account_address, " + - "recipient_account_type, recipient_account_address, transaction_type, fee, timestamp, " + + want: "SELECT id, block_id, block_height, sender_account_address, " + + "recipient_account_address, transaction_type, fee, timestamp, " + "transaction_hash, transaction_body_length, transaction_body_bytes, signature, version from " + "\"transaction\" ORDER BY block_height, timestamp LIMIT 20,10", }, @@ -94,8 +94,8 @@ func TestGetTransactions(t *testing.T) { Limit: 10, Offset: 20, }, - want: "SELECT id, block_id, block_height, sender_account_type, sender_account_address, " + - "recipient_account_type, recipient_account_address, transaction_type, fee, timestamp, " + + want: "SELECT id, block_id, block_height, sender_account_address, " + + "recipient_account_address, transaction_type, fee, timestamp, " + "transaction_hash, transaction_body_length, transaction_body_bytes, signature, version from " + "\"transaction\" ORDER BY block_height, timestamp LIMIT 20,10", }, From c5425f859cf0bb0be13f4c1b9536def527ae350e Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 09:48:30 +0800 Subject: [PATCH 19/27] #134 adjust transaction type implementation for account type deletion --- common/transaction/nodeRegistrationUpdate.go | 4 +- common/transaction/nodeRegistration_test.go | 53 +++------- common/transaction/sendMoney_test.go | 106 ++++++------------- common/transaction/transaction_test.go | 23 +--- 4 files changed, 49 insertions(+), 137 deletions(-) diff --git a/common/transaction/nodeRegistrationUpdate.go b/common/transaction/nodeRegistrationUpdate.go index 4a119306f..ed038660a 100644 --- a/common/transaction/nodeRegistrationUpdate.go +++ b/common/transaction/nodeRegistrationUpdate.go @@ -94,7 +94,7 @@ func (tx *UpdateNodeRegistration) ApplyConfirmed() error { -(effectiveBalanceToLock + tx.Fee), map[string]interface{}{ "account_address": tx.SenderAddress, - "block_height": tx.Height, + "block_height": tx.Height, }, ) updateNodeQ, updateNodeArg := tx.NodeRegistrationQuery.UpdateNodeRegistration(nodeRegistration) @@ -147,7 +147,7 @@ func (tx *UpdateNodeRegistration) ApplyUnconfirmed() error { accountBalanceSenderQ, accountBalanceSenderQArgs := tx.AccountBalanceQuery.AddAccountSpendableBalance( -(effectiveBalanceToLock + tx.Fee), map[string]interface{}{ - "account_address": tx.SenderAddress, + "account_address": tx.SenderAddress, }, ) // add row to node_registry table diff --git a/common/transaction/nodeRegistration_test.go b/common/transaction/nodeRegistration_test.go index ff7393cee..396f82e36 100644 --- a/common/transaction/nodeRegistration_test.go +++ b/common/transaction/nodeRegistration_test.go @@ -163,17 +163,17 @@ func (*mockExecutorValidateSuccess) ExecuteSelect(qe string, args ...interface{} db, mock, _ := sqlmock.New() defer db.Close() - if qe == "SELECT account_id,block_height,spendable_balance,balance,pop_revenue,latest FROM account_balance WHERE "+ - "account_id = ? AND latest = 1" { + if qe == "SELECT account_address,block_height,spendable_balance,balance,pop_revenue,latest FROM account_balance WHERE "+ + "account_address = ? AND latest = 1" { mock.ExpectQuery("A").WillReturnRows(sqlmock.NewRows([]string{ - "AccountID", + "AccountAddress", "BlockHeight", "SpendableBalance", "Balance", "PopRevenue", "Latest", }).AddRow( - []byte{1}, + "BCZ", 1, 1000000, 1000000, @@ -184,7 +184,7 @@ func (*mockExecutorValidateSuccess) ExecuteSelect(qe string, args ...interface{} } mock.ExpectQuery("B").WillReturnRows(sqlmock.NewRows([]string{ "NodePublicKey", - "AccountId", + "AccountAddress", "RegistrationHeight", "NodeAddress", "LockedBalance", @@ -231,7 +231,6 @@ func TestNodeRegistration_ApplyConfirmed(t *testing.T) { SenderAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface NodeRegistrationQuery query.NodeRegistrationQueryInterface QueryExecutor query.ExecutorInterface } @@ -305,10 +304,8 @@ func TestNodeRegistration_ApplyConfirmed(t *testing.T) { Body: tt.fields.Body, Fee: tt.fields.Fee, SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, Height: tt.fields.Height, AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, QueryExecutor: tt.fields.QueryExecutor, } @@ -327,7 +324,6 @@ func TestNodeRegistration_ApplyUnconfirmed(t *testing.T) { SenderAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface NodeRegistrationQuery query.NodeRegistrationQueryInterface QueryExecutor query.ExecutorInterface } @@ -385,10 +381,8 @@ func TestNodeRegistration_ApplyUnconfirmed(t *testing.T) { Body: tt.fields.Body, Fee: tt.fields.Fee, SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, Height: tt.fields.Height, AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, QueryExecutor: tt.fields.QueryExecutor, } @@ -407,7 +401,6 @@ func TestNodeRegistration_UndoApplyUnconfirmed(t *testing.T) { SenderAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface NodeRegistrationQuery query.NodeRegistrationQueryInterface QueryExecutor query.ExecutorInterface } @@ -453,10 +446,8 @@ func TestNodeRegistration_UndoApplyUnconfirmed(t *testing.T) { Body: tt.fields.Body, Fee: tt.fields.Fee, SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, Height: tt.fields.Height, AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, QueryExecutor: tt.fields.QueryExecutor, } @@ -475,7 +466,6 @@ func TestNodeRegistration_Validate(t *testing.T) { SenderAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface NodeRegistrationQuery query.NodeRegistrationQueryInterface QueryExecutor query.ExecutorInterface } @@ -560,10 +550,8 @@ func TestNodeRegistration_Validate(t *testing.T) { Body: tt.fields.Body, Fee: tt.fields.Fee, SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, Height: tt.fields.Height, AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, QueryExecutor: tt.fields.QueryExecutor, } @@ -582,7 +570,6 @@ func TestNodeRegistration_GetAmount(t *testing.T) { SenderAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface NodeRegistrationQuery query.NodeRegistrationQueryInterface QueryExecutor query.ExecutorInterface } @@ -607,10 +594,8 @@ func TestNodeRegistration_GetAmount(t *testing.T) { Body: tt.fields.Body, Fee: tt.fields.Fee, SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, Height: tt.fields.Height, AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, QueryExecutor: tt.fields.QueryExecutor, } @@ -629,7 +614,6 @@ func TestNodeRegistration_GetSize(t *testing.T) { SenderAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface NodeRegistrationQuery query.NodeRegistrationQueryInterface QueryExecutor query.ExecutorInterface } @@ -654,10 +638,8 @@ func TestNodeRegistration_GetSize(t *testing.T) { Body: tt.fields.Body, Fee: tt.fields.Fee, SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, Height: tt.fields.Height, AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, QueryExecutor: tt.fields.QueryExecutor, } @@ -674,11 +656,10 @@ func TestNodeRegistration_ParseBodyBytes(t *testing.T) { type fields struct { Body *model.NodeRegistrationTransactionBody Fee int64 + SenderAddressLength uint32 SenderAddress string - SenderAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface NodeRegistrationQuery query.NodeRegistrationQueryInterface QueryExecutor query.ExecutorInterface } @@ -703,15 +684,14 @@ func TestNodeRegistration_ParseBodyBytes(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { n := &NodeRegistration{ - Body: tt.fields.Body, - Fee: tt.fields.Fee, - SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, - Height: tt.fields.Height, - AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, - NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, - QueryExecutor: tt.fields.QueryExecutor, + Body: tt.fields.Body, + Fee: tt.fields.Fee, + SenderAccountAddressLength: tt.fields.SenderAddressLength, + SenderAddress: tt.fields.SenderAddress, + Height: tt.fields.Height, + AccountBalanceQuery: tt.fields.AccountBalanceQuery, + NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, + QueryExecutor: tt.fields.QueryExecutor, } if got := n.ParseBodyBytes(tt.args.txBodyBytes); !reflect.DeepEqual(got, tt.want) { t.Errorf("NodeRegistration.ParseBodyBytes() = %v, want %v", got, tt.want) @@ -726,10 +706,8 @@ func TestNodeRegistration_GetBodyBytes(t *testing.T) { Body *model.NodeRegistrationTransactionBody Fee int64 SenderAddress string - SenderAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface NodeRegistrationQuery query.NodeRegistrationQueryInterface QueryExecutor query.ExecutorInterface } @@ -759,10 +737,7 @@ func TestNodeRegistration_GetBodyBytes(t *testing.T) { Body: tt.fields.Body, Fee: tt.fields.Fee, SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, - Height: tt.fields.Height, AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, NodeRegistrationQuery: tt.fields.NodeRegistrationQuery, QueryExecutor: tt.fields.QueryExecutor, } diff --git a/common/transaction/sendMoney_test.go b/common/transaction/sendMoney_test.go index 69951b0f0..393aa0082 100644 --- a/common/transaction/sendMoney_test.go +++ b/common/transaction/sendMoney_test.go @@ -75,19 +75,6 @@ func (*executorAccountCreateSuccess) ExecuteTransactions([][]interface{}) error return nil } -func (*executorAccountCreateSuccess) ExecuteSelect(qStr string, args ...interface{}) (*sql.Rows, error) { - db, mock, err := sqlmock.New() - if err != nil { - return nil, err - } - defer db.Close() - - mock.ExpectQuery(regexp.QuoteMeta(qStr)).WithArgs(1).WillReturnRows(sqlmock.NewRows( - query.NewAccountQuery().Fields, - )) - return db.Query(qStr, 1) -} - func (*executorAccountCreateSuccess) ExecuteSelectRow(qStr string, args ...interface{}) *sql.Row { db, mock, _ := sqlmock.New() @@ -164,7 +151,6 @@ func TestSendMoney_Validate(t *testing.T) { RecipientAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface QueryExecutor query.ExecutorInterface } tests := []struct { @@ -217,7 +203,6 @@ func TestSendMoney_Validate(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorAccountCreateSuccess{ query.Executor{ @@ -238,7 +223,6 @@ func TestSendMoney_Validate(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorAccountCountFail{ query.Executor{ @@ -259,7 +243,6 @@ func TestSendMoney_Validate(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorAccountCountSuccess{ query.Executor{ @@ -280,7 +263,6 @@ func TestSendMoney_Validate(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorValidateSuccess{ query.Executor{ @@ -294,15 +276,12 @@ func TestSendMoney_Validate(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tx := &SendMoney{ - Body: tt.fields.Body, - SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, - RecipientAddress: tt.fields.RecipientAddress, - RecipientAccountType: tt.fields.RecipientAccountType, - Height: tt.fields.Height, - AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, - QueryExecutor: tt.fields.QueryExecutor, + Body: tt.fields.Body, + SenderAddress: tt.fields.SenderAddress, + RecipientAddress: tt.fields.RecipientAddress, + Height: tt.fields.Height, + AccountBalanceQuery: tt.fields.AccountBalanceQuery, + QueryExecutor: tt.fields.QueryExecutor, } if err := tx.Validate(); (err != nil) != tt.wantErr { t.Errorf("SendMoney.Validate() error = %v, wantErr %v", err, tt.wantErr) @@ -323,7 +302,6 @@ func TestSendMoney_ApplyUnconfirmed(t *testing.T) { RecipientAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface QueryExecutor query.ExecutorInterface } tests := []struct { @@ -342,7 +320,6 @@ func TestSendMoney_ApplyUnconfirmed(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorUnconfirmedFail{}, }, @@ -359,7 +336,6 @@ func TestSendMoney_ApplyUnconfirmed(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorApplyUnconfirmedSuccess{}, }, @@ -369,15 +345,12 @@ func TestSendMoney_ApplyUnconfirmed(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tx := &SendMoney{ - Body: tt.fields.Body, - SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, - RecipientAddress: tt.fields.RecipientAddress, - RecipientAccountType: tt.fields.RecipientAccountType, - Height: tt.fields.Height, - AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, - QueryExecutor: tt.fields.QueryExecutor, + Body: tt.fields.Body, + SenderAddress: tt.fields.SenderAddress, + RecipientAddress: tt.fields.RecipientAddress, + Height: tt.fields.Height, + AccountBalanceQuery: tt.fields.AccountBalanceQuery, + QueryExecutor: tt.fields.QueryExecutor, } if err := tx.ApplyUnconfirmed(); (err != nil) != tt.wantErr { t.Errorf("SendMoney.ApplyUnconfirmed() error = %v, wantErr %v", err, tt.wantErr) @@ -398,7 +371,6 @@ func TestSendMoney_ApplyConfirmed(t *testing.T) { RecipientAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface QueryExecutor query.ExecutorInterface } tests := []struct { @@ -417,7 +389,6 @@ func TestSendMoney_ApplyConfirmed(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorAccountCountSuccess{ query.Executor{ @@ -438,7 +409,6 @@ func TestSendMoney_ApplyConfirmed(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorAccountCountFail{ query.Executor{ @@ -459,7 +429,6 @@ func TestSendMoney_ApplyConfirmed(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorFailUpdateAccount{}, }, @@ -476,7 +445,6 @@ func TestSendMoney_ApplyConfirmed(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorSuccessUpdateAccount{}, }, @@ -487,15 +455,12 @@ func TestSendMoney_ApplyConfirmed(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tx := &SendMoney{ - Body: tt.fields.Body, - SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, - RecipientAddress: tt.fields.RecipientAddress, - RecipientAccountType: tt.fields.RecipientAccountType, - Height: tt.fields.Height, - AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, - QueryExecutor: tt.fields.QueryExecutor, + Body: tt.fields.Body, + SenderAddress: tt.fields.SenderAddress, + RecipientAddress: tt.fields.RecipientAddress, + Height: tt.fields.Height, + AccountBalanceQuery: tt.fields.AccountBalanceQuery, + QueryExecutor: tt.fields.QueryExecutor, } if err := tx.ApplyConfirmed(); (err != nil) != tt.wantErr { t.Errorf("SendMoney.ApplyConfirmed() error = %v, wantErr %v", err, tt.wantErr) @@ -513,7 +478,6 @@ func TestSendMoney_GetAmount(t *testing.T) { RecipientAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface QueryExecutor query.ExecutorInterface } tests := []struct { @@ -532,7 +496,6 @@ func TestSendMoney_GetAmount(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorSuccessUpdateAccount{}, }, @@ -542,15 +505,12 @@ func TestSendMoney_GetAmount(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tx := &SendMoney{ - Body: tt.fields.Body, - SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, - RecipientAddress: tt.fields.RecipientAddress, - RecipientAccountType: tt.fields.RecipientAccountType, - Height: tt.fields.Height, - AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, - QueryExecutor: tt.fields.QueryExecutor, + Body: tt.fields.Body, + SenderAddress: tt.fields.SenderAddress, + RecipientAddress: tt.fields.RecipientAddress, + Height: tt.fields.Height, + AccountBalanceQuery: tt.fields.AccountBalanceQuery, + QueryExecutor: tt.fields.QueryExecutor, } if got := tx.GetAmount(); got != tt.want { t.Errorf("SendMoney.GetAmount() = %v, want %v", got, tt.want) @@ -578,7 +538,6 @@ func TestSendMoney_UndoApplyUnconfirmed(t *testing.T) { RecipientAccountType uint32 Height uint32 AccountBalanceQuery query.AccountBalanceQueryInterface - AccountQuery query.AccountQueryInterface QueryExecutor query.ExecutorInterface } tests := []struct { @@ -597,7 +556,6 @@ func TestSendMoney_UndoApplyUnconfirmed(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorAccountCountSuccess{}, }, @@ -614,7 +572,6 @@ func TestSendMoney_UndoApplyUnconfirmed(t *testing.T) { SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", RecipientAccountType: 0, RecipientAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - AccountQuery: query.NewAccountQuery(), AccountBalanceQuery: query.NewAccountBalanceQuery(), QueryExecutor: &executorAccountCountFail{}, }, @@ -624,15 +581,12 @@ func TestSendMoney_UndoApplyUnconfirmed(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tx := &SendMoney{ - Body: tt.fields.Body, - SenderAddress: tt.fields.SenderAddress, - SenderAccountType: tt.fields.SenderAccountType, - RecipientAddress: tt.fields.RecipientAddress, - RecipientAccountType: tt.fields.RecipientAccountType, - Height: tt.fields.Height, - AccountBalanceQuery: tt.fields.AccountBalanceQuery, - AccountQuery: tt.fields.AccountQuery, - QueryExecutor: tt.fields.QueryExecutor, + Body: tt.fields.Body, + SenderAddress: tt.fields.SenderAddress, + RecipientAddress: tt.fields.RecipientAddress, + Height: tt.fields.Height, + AccountBalanceQuery: tt.fields.AccountBalanceQuery, + QueryExecutor: tt.fields.QueryExecutor, } if err := tx.UndoApplyUnconfirmed(); (err != nil) != tt.wantErr { t.Errorf("SendMoney.UndoApplyUnconfirmed() error = %v, wantErr %v", err, tt.wantErr) diff --git a/common/transaction/transaction_test.go b/common/transaction/transaction_test.go index cb2dd3661..9b5f8405a 100644 --- a/common/transaction/transaction_test.go +++ b/common/transaction/transaction_test.go @@ -33,9 +33,7 @@ func TestTypeSwitcher_GetTransactionType(t *testing.T) { args: args{ tx: &model.Transaction{ Height: 0, - SenderAccountType: 0, SenderAccountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - RecipientAccountType: 0, RecipientAccountAddress: "", TransactionBody: &model.Transaction_SendMoneyTransactionBody{ SendMoneyTransactionBody: &model.SendMoneyTransactionBody{ @@ -47,17 +45,14 @@ func TestTypeSwitcher_GetTransactionType(t *testing.T) { }, }, want: &SendMoney{ - Height: 0, - SenderAccountType: 0, - SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - RecipientAddress: "", - RecipientAccountType: 0, + Height: 0, + SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", + RecipientAddress: "", Body: &model.SendMoneyTransactionBody{ Amount: 10, }, QueryExecutor: &query.Executor{}, AccountBalanceQuery: query.NewAccountBalanceQuery(), - AccountQuery: query.NewAccountQuery(), }, }, { @@ -68,9 +63,7 @@ func TestTypeSwitcher_GetTransactionType(t *testing.T) { args: args{ tx: &model.Transaction{ Height: 0, - SenderAccountType: 0, SenderAccountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - RecipientAccountType: 0, RecipientAccountAddress: "", TransactionBody: &model.Transaction_SendMoneyTransactionBody{ SendMoneyTransactionBody: &model.SendMoneyTransactionBody{ @@ -90,9 +83,7 @@ func TestTypeSwitcher_GetTransactionType(t *testing.T) { args: args{ tx: &model.Transaction{ Height: 0, - SenderAccountType: 0, SenderAccountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - RecipientAccountType: 0, RecipientAccountAddress: "", TransactionBody: &model.Transaction_SendMoneyTransactionBody{ SendMoneyTransactionBody: &model.SendMoneyTransactionBody{ @@ -112,9 +103,7 @@ func TestTypeSwitcher_GetTransactionType(t *testing.T) { args: args{ tx: &model.Transaction{ Height: 0, - SenderAccountType: 0, SenderAccountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - RecipientAccountType: 0, RecipientAccountAddress: "", TransactionBody: &model.Transaction_SendMoneyTransactionBody{ SendMoneyTransactionBody: &model.SendMoneyTransactionBody{ @@ -134,9 +123,7 @@ func TestTypeSwitcher_GetTransactionType(t *testing.T) { args: args{ tx: &model.Transaction{ Height: 0, - SenderAccountType: 0, SenderAccountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - RecipientAccountType: 0, RecipientAccountAddress: "", TransactionBody: &model.Transaction_NodeRegistrationTransactionBody{ NodeRegistrationTransactionBody: nodeRegistrationBody, @@ -147,12 +134,10 @@ func TestTypeSwitcher_GetTransactionType(t *testing.T) { }, want: &NodeRegistration{ Height: 0, - SenderAccountType: 0, SenderAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", Body: nodeRegistrationBody, QueryExecutor: &query.Executor{}, AccountBalanceQuery: query.NewAccountBalanceQuery(), - AccountQuery: query.NewAccountQuery(), NodeRegistrationQuery: query.NewNodeRegistrationQuery(), }, }, @@ -164,9 +149,7 @@ func TestTypeSwitcher_GetTransactionType(t *testing.T) { args: args{ tx: &model.Transaction{ Height: 0, - SenderAccountType: 0, SenderAccountAddress: "BCZEGOb3WNx3fDOVf9ZS4EjvOIv_UeW4TVBQJ_6tHKlE", - RecipientAccountType: 0, RecipientAccountAddress: "", TransactionBody: &model.Transaction_SendMoneyTransactionBody{ SendMoneyTransactionBody: &model.SendMoneyTransactionBody{ From de7683a777a9b283af69d3dcd1ea4c1f8531c23e Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 09:49:23 +0800 Subject: [PATCH 20/27] #134 blocksmith ID to blocksmith address in native/service package --- p2p/native/service/client_test.go | 4 ++-- p2p/native/service/server_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/native/service/client_test.go b/p2p/native/service/client_test.go index 217983950..1255c0618 100644 --- a/p2p/native/service/client_test.go +++ b/p2p/native/service/client_test.go @@ -392,7 +392,7 @@ func TestPeerServiceClient_SendBlock(t *testing.T) { SmithScale: 0, PreviousBlockHash: []byte{}, BlockSeed: []byte{}, - BlocksmithID: make([]byte, 32), + BlocksmithAddress: "BCZ", Timestamp: 12345678, TotalAmount: 0, TotalFee: 0, @@ -426,7 +426,7 @@ func TestPeerServiceClient_SendBlock(t *testing.T) { SmithScale: 0, PreviousBlockHash: []byte{}, BlockSeed: []byte{}, - BlocksmithID: make([]byte, 32), + BlocksmithAddress: "BCZ", Timestamp: 12345678, TotalAmount: 0, TotalFee: 0, diff --git a/p2p/native/service/server_test.go b/p2p/native/service/server_test.go index 28c79039c..6efb810af 100644 --- a/p2p/native/service/server_test.go +++ b/p2p/native/service/server_test.go @@ -249,7 +249,7 @@ func TestServerService_SendBlock(t *testing.T) { SmithScale: 0, PreviousBlockHash: []byte{}, BlockSeed: []byte{}, - BlocksmithID: make([]byte, 32), + BlocksmithAddress: "BCZ", Timestamp: 12345678, TotalAmount: 0, TotalFee: 0, From f42c769d3a9596ab1319700df9fbe3da8e59cda3 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 09:50:02 +0800 Subject: [PATCH 21/27] #134 update schema commit --- common/schema | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/schema b/common/schema index 481cc97b1..3da444135 160000 --- a/common/schema +++ b/common/schema @@ -1 +1 @@ -Subproject commit 481cc97b1bd01196d208ae9d1b7efa73789d3c42 +Subproject commit 3da444135f7d289a6a8e7744a0711fa069854532 From 585532ecf0a329e5fddff22f64c1fbb7ceeb3569 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 09:57:13 +0800 Subject: [PATCH 22/27] #134 remove account ID constant size --- common/constant/fieldsSize.go | 1 - 1 file changed, 1 deletion(-) diff --git a/common/constant/fieldsSize.go b/common/constant/fieldsSize.go index 51109b415..20f2f5c0c 100644 --- a/common/constant/fieldsSize.go +++ b/common/constant/fieldsSize.go @@ -3,7 +3,6 @@ package constant var ( AccountAddressLength uint32 = 4 NodeAddressLength uint32 = 4 - AccountID uint32 = 8 AccountAddress uint32 = 44 // NodePublicKey TODO: this is valid for pub keys generated using Ed25519. in future we might have more implementations NodePublicKey uint32 = 32 From ff2c94b2030ec50b5590fd133338e76794fb2bd1 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 10:24:27 +0800 Subject: [PATCH 23/27] #134 fix mempool table --- api/service/transactionApiService.go | 2 +- common/database/migration.go | 14 +++++--------- common/query/mempoolQuery.go | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/api/service/transactionApiService.go b/api/service/transactionApiService.go index 267d88d7e..4b94486e5 100644 --- a/api/service/transactionApiService.go +++ b/api/service/transactionApiService.go @@ -166,7 +166,7 @@ func (ts *TransactionService) PostTransaction( ID: tx.ID, TransactionBytes: txBytes, ArrivalTimestamp: time.Now().Unix(), - SenderAccountAddress: tx.RecipientAccountAddress, + SenderAccountAddress: tx.SenderAccountAddress, RecipientAccountAddress: tx.RecipientAccountAddress, } if err := ts.MempoolService.ValidateMempoolTransaction(mpTx); err != nil { diff --git a/common/database/migration.go b/common/database/migration.go index 976ef06cf..b128be301 100644 --- a/common/database/migration.go +++ b/common/database/migration.go @@ -45,21 +45,17 @@ func (m *Migration) Init() error { "fee_per_byte" INTEGER, "arrival_timestamp" INTEGER, "transaction_bytes" BLOB, - "sender_account_id" BLOB, - "recipient_account_id" BLOB, - PRIMARY KEY("id"), - FOREIGN KEY("sender_account_id") REFERENCES account(id), - FOREIGN KEY("recipient_account_id") REFERENCES account(id) + "sender_account_address" VARCHAR(255), + "recipient_account_address" VARCHAR(255), + PRIMARY KEY("id") );`, ` CREATE TABLE IF NOT EXISTS "transaction" ( "id" INTEGER, "block_id" INTEGER, "block_height" INTEGER, - "sender_account_address_length" INTEGER, - "sender_account_address" TEXT, - "recipient_account_address_length" INTEGER, - "recipient_account_address" TEXT, + "sender_account_address" VARCHAR(255), + "recipient_account_address" VARCHAR(255), "transaction_type" INTEGER, "fee" INTEGER, "timestamp" INTEGER, diff --git a/common/query/mempoolQuery.go b/common/query/mempoolQuery.go index 7c83463b2..5fa80aed2 100644 --- a/common/query/mempoolQuery.go +++ b/common/query/mempoolQuery.go @@ -32,8 +32,8 @@ type ( func NewMempoolQuery(chaintype contract.ChainType) *MempoolQuery { return &MempoolQuery{ Fields: []string{ - "id", "fee_per_byte", "arrival_timestamp", "transaction_bytes", "sender_account_id", - "recipient_account_id", + "id", "fee_per_byte", "arrival_timestamp", "transaction_bytes", "sender_account_address", + "recipient_account_address", }, TableName: "mempool", ChainType: chaintype, From ade3c1f1c82cb22170704bc23b8066f48fb30aa3 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 10:29:47 +0800 Subject: [PATCH 24/27] #134 fix mempool tests --- common/query/mempoolQuery_test.go | 16 ++++++++-------- core/service/mempoolCoreService_test.go | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/common/query/mempoolQuery_test.go b/common/query/mempoolQuery_test.go index 87b266d0d..81f0f8e39 100644 --- a/common/query/mempoolQuery_test.go +++ b/common/query/mempoolQuery_test.go @@ -16,7 +16,7 @@ var mockMempoolQuery = &MempoolQuery{ TableName: "mempool", Fields: []string{ "id", "fee_per_byte", "arrival_timestamp", "transaction_bytes", - "sender_account_id", "recipient_account_id", + "sender_account_address", "recipient_account_address", }, } @@ -67,8 +67,8 @@ func TestMempoolQuery_getTableName(t *testing.T) { func TestMempoolQuery_GetMempoolTransactions(t *testing.T) { t.Run("GetMempoolTransactions:success", func(t *testing.T) { q := mockMempoolQuery.GetMempoolTransactions() - wantQ := "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_id" + - ", recipient_account_id FROM mempool" + wantQ := "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_address" + + ", recipient_account_address FROM mempool" if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) } @@ -78,8 +78,8 @@ func TestMempoolQuery_GetMempoolTransactions(t *testing.T) { func TestMempoolQuery_GetMempoolTransaction(t *testing.T) { t.Run("GetMempoolTransaction:success", func(t *testing.T) { q := mockMempoolQuery.GetMempoolTransaction() - wantQ := "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_id," + - " recipient_account_id FROM mempool WHERE id = :id" + wantQ := "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_address," + + " recipient_account_address FROM mempool WHERE id = :id" if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) } @@ -89,9 +89,9 @@ func TestMempoolQuery_GetMempoolTransaction(t *testing.T) { func TestMempoolQuery_InsertMempoolTransaction(t *testing.T) { t.Run("InsertMempoolTransaction:success", func(t *testing.T) { q := mockMempoolQuery.InsertMempoolTransaction() - wantQ := "INSERT INTO mempool (id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_id," + - " recipient_account_id) VALUES(:id, :fee_per_byte, :arrival_timestamp, :transaction_bytes," + - " :sender_account_id, :recipient_account_id)" + wantQ := "INSERT INTO mempool (id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_address," + + " recipient_account_address) VALUES(:id, :fee_per_byte, :arrival_timestamp, :transaction_bytes," + + " :sender_account_address, :recipient_account_address)" if q != wantQ { t.Errorf("query returned wrong: get: %s\nwant: %s", q, wantQ) } diff --git a/core/service/mempoolCoreService_test.go b/core/service/mempoolCoreService_test.go index b296bd2a9..fcab9b6c3 100644 --- a/core/service/mempoolCoreService_test.go +++ b/core/service/mempoolCoreService_test.go @@ -23,17 +23,17 @@ type ( } ) -var getTxByIDQuery = "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_id, " + - "recipient_account_id FROM mempool WHERE id = :id" +var getTxByIDQuery = "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_address, " + + "recipient_account_address FROM mempool WHERE id = :id" func (*mockMempoolQueryExecutorSuccess) ExecuteSelect(qe string, args ...interface{}) (*sql.Rows, error) { db, mock, _ := sqlmock.New() defer db.Close() switch qe { - case "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_id, recipient_account_id FROM mempool": - mockedRows := sqlmock.NewRows([]string{"id", "fee_per_byte", "arrival_timestamp", "transaction_bytes", "sender_account_id", - "recipient_account_id"}) + case "SELECT id, fee_per_byte, arrival_timestamp, transaction_bytes, sender_account_address, recipient_account_address FROM mempool": + mockedRows := sqlmock.NewRows([]string{"id", "fee_per_byte", "arrival_timestamp", "transaction_bytes", "sender_account_address", + "recipient_account_address"}) mockedRows.AddRow(1, 1, 1562893305, getTestSignedMempoolTransaction(1, 1562893305).TransactionBytes, "A", "B") mockedRows.AddRow(2, 10, 1562893304, getTestSignedMempoolTransaction(2, 1562893304).TransactionBytes, "A", "B") mockedRows.AddRow(3, 1, 1562893302, getTestSignedMempoolTransaction(3, 1562893302).TransactionBytes, "A", "B") @@ -75,7 +75,7 @@ func (*mockMempoolQueryExecutorFail) ExecuteSelect(qe string, args ...interface{ // before adding mempool transactions to db we check for duplicate transactions case getTxByIDQuery: mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ - "id", "fee_per_byte", "arrival_timestamp", "transaction_bytes", "sender_account_id", "recipient_account_id"}, + "id", "fee_per_byte", "arrival_timestamp", "transaction_bytes", "sender_account_address", "recipient_account_address"}, ).AddRow(3, 1, 1562893302, []byte{}, []byte{1}, []byte{2})) default: return nil, errors.New("MockedError") From 99a32fe7aefa17fad43273236a1e84e12a186a47 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 11:18:19 +0800 Subject: [PATCH 25/27] #134 remove debug code --- common/transaction/fixtureGenerator.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/transaction/fixtureGenerator.go b/common/transaction/fixtureGenerator.go index ac05ca8b4..0a48d10c3 100644 --- a/common/transaction/fixtureGenerator.go +++ b/common/transaction/fixtureGenerator.go @@ -1,7 +1,6 @@ package transaction import ( - "fmt" "github.com/zoobc/zoobc-core/common/crypto" "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/common/util" @@ -44,6 +43,5 @@ func GetFixtures() (poownMessage *model.ProofOfOwnershipMessage, poown *model.Pr Body: txBody, } txBodyBytes = nr.GetBodyBytes() - fmt.Printf("txBodyBytes: %v", txBodyBytes) return poownMessage, poown, txBody, txBodyBytes } From 6409e438b089111e40a00ede3f404f7035cc2ea6 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 11:20:19 +0800 Subject: [PATCH 26/27] #134 remove account id usage --- common/transaction/nodeRegistration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/transaction/nodeRegistration.go b/common/transaction/nodeRegistration.go index 525f6699e..a4ccb0bb0 100644 --- a/common/transaction/nodeRegistration.go +++ b/common/transaction/nodeRegistration.go @@ -86,7 +86,7 @@ func (tx *NodeRegistration) ApplyUnconfirmed() error { accountBalanceSenderQ, accountBalanceSenderQArgs := tx.AccountBalanceQuery.AddAccountSpendableBalance( -(tx.Body.LockedBalance + tx.Fee), map[string]interface{}{ - "account_id": tx.SenderAddress, + "account_address": tx.SenderAddress, }, ) // add row to node_registry table From 6e50eacada7ca19efa7443da97acda06fd17f8e3 Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Mon, 12 Aug 2019 11:38:06 +0800 Subject: [PATCH 27/27] #134 length of string error, should be length of []byte(string) --- cmd/transaction/transactionGenerator.go | 10 +++++----- common/transaction/fixtureGenerator.go | 2 +- core/service/blockCoreService.go | 4 ++-- core/service/genesisCoreService.go | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/transaction/transactionGenerator.go b/cmd/transaction/transactionGenerator.go index dc5836b39..769bf67cf 100644 --- a/cmd/transaction/transactionGenerator.go +++ b/cmd/transaction/transactionGenerator.go @@ -66,9 +66,9 @@ func getTransaction(txType []byte) *model.Transaction { Version: 1, TransactionType: util.ConvertBytesToUint32(txTypeMap["sendMoney"]), Timestamp: time.Now().Unix(), - SenderAccountAddressLength: uint32(len("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN")), + SenderAccountAddressLength: uint32(len([]byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"))), SenderAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", - RecipientAccountAddressLength: uint32(len("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J")), + RecipientAccountAddressLength: uint32(len([]byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"))), RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", Fee: 1, TransactionBodyLength: 8, @@ -81,7 +81,7 @@ func getTransaction(txType []byte) *model.Transaction { } case util.ConvertBytesToUint32(txTypeMap["registerNode"]): txBody := &model.NodeRegistrationTransactionBody{ - AccountAddressLength: uint32(len("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN")), + AccountAddressLength: uint32(len([]byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"))), AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", NodePublicKey: []byte{ 0, 14, 6, 218, 170, 54, 60, 50, 2, 66, 130, 119, 226, 235, 126, 203, 5, 12, 152, 194, 170, 146, 43, 63, 224, @@ -98,9 +98,9 @@ func getTransaction(txType []byte) *model.Transaction { Version: 1, TransactionType: util.ConvertBytesToUint32(txTypeMap["registerNode"]), Timestamp: time.Now().Unix(), - SenderAccountAddressLength: uint32(len("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN")), + SenderAccountAddressLength: uint32(len([]byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"))), SenderAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", - RecipientAccountAddressLength: uint32(len("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J")), + RecipientAccountAddressLength: uint32(len([]byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"))), RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J", Fee: 1, TransactionBodyLength: uint32(len(txBodyBytes)), diff --git a/common/transaction/fixtureGenerator.go b/common/transaction/fixtureGenerator.go index 0a48d10c3..2f0e1af09 100644 --- a/common/transaction/fixtureGenerator.go +++ b/common/transaction/fixtureGenerator.go @@ -31,7 +31,7 @@ func GetFixtures() (poownMessage *model.ProofOfOwnershipMessage, poown *model.Pr txBody = &model.NodeRegistrationTransactionBody{ NodePublicKey: []byte{0, 14, 6, 218, 170, 54, 60, 50, 2, 66, 130, 119, 226, 235, 126, 203, 5, 12, 152, 194, 170, 146, 43, 63, 224, 101, 127, 241, 62, 152, 187, 255}, - AccountAddressLength: uint32(len("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN")), + AccountAddressLength: uint32(len([]byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"))), AccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", RegistrationHeight: 0, NodeAddressLength: 9, diff --git a/core/service/blockCoreService.go b/core/service/blockCoreService.go index 91b639de9..387ebd776 100644 --- a/core/service/blockCoreService.go +++ b/core/service/blockCoreService.go @@ -110,7 +110,7 @@ func (bs *BlockService) NewBlock( Version: version, PreviousBlockHash: previousBlockHash, BlockSeed: blockSeed, - BlocksmithAddressLength: uint32(len(blocksmithAddress)), + BlocksmithAddressLength: uint32(len([]byte(blocksmithAddress))), BlocksmithAddress: blocksmithAddress, Height: previousBlockHeight, Timestamp: timestamp, @@ -144,7 +144,7 @@ func (bs *BlockService) NewGenesisBlock( Version: version, PreviousBlockHash: previousBlockHash, BlockSeed: blockSeed, - BlocksmithAddressLength: uint32(len(blocksmithAddress)), + BlocksmithAddressLength: uint32(len([]byte(blocksmithAddress))), BlocksmithAddress: blocksmithAddress, Height: previousBlockHeight, Timestamp: timestamp, diff --git a/core/service/genesisCoreService.go b/core/service/genesisCoreService.go index 89acc98e0..f1829a8b7 100644 --- a/core/service/genesisCoreService.go +++ b/core/service/genesisCoreService.go @@ -37,9 +37,9 @@ func GetGenesisTransactions(chainType contract.ChainType) []*model.Transaction { TransactionType: util.ConvertBytesToUint32([]byte{1, 0, 0, 0}), Height: 0, Timestamp: 1562806389280, - SenderAccountAddressLength: uint32(len(constant.GenesisAccountAddress)), + SenderAccountAddressLength: uint32(len([]byte(constant.GenesisAccountAddress))), SenderAccountAddress: constant.GenesisAccountAddress, - RecipientAccountAddressLength: uint32(len(receiver)), + RecipientAccountAddressLength: uint32(len([]byte(receiver))), RecipientAccountAddress: receiver, Fee: 0, TransactionBodyLength: 8,