diff --git a/.golangci.yml b/.golangci.yml index f2445031d..892792cb7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,6 +39,9 @@ linters-settings: goimports: local-prefixes: github.com/zoobc/zoobc-core gocritic: + settings: + hugeParam: + sizeThreshold: 512 enabled-tags: - performance - style diff --git a/ZooBC.postman_collection.json b/ZooBC.postman_collection.json index 54f8e6f6a..2545e76a5 100644 --- a/ZooBC.postman_collection.json +++ b/ZooBC.postman_collection.json @@ -1,90 +1,90 @@ { - "info": { - "_postman_id": "e8cb55b1-5c13-4894-8106-52f4bf019eee", - "name": "ZooBC", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "item": [ - { - "name": "blocks", - "item": [ - { - "name": "GetBlocks", - "request": { - "method": "GET", - "header": [], - "body": { - "mode": "raw", - "raw": "" - }, - "url": { - "raw": "{{host}}/v1/block/GetBlocks?Limit=10&Height=0&Chaintype=0", - "host": [ - "{{host}}" - ], - "path": [ - "v1", - "block", - "GetBlocks" - ], - "query": [ - { - "key": "Limit", - "value": "10" - }, - { - "key": "Height", - "value": "0" - }, - { - "key": "Chaintype", - "value": "0" - } - ] - } - }, - "response": [] - }, - { - "name": "GetBlock", - "request": { - "method": "GET", - "header": [], - "body": { - "mode": "raw", - "raw": "" - }, - "url": { - "raw": "{{host}}/v1/block/GetBlock?ID=-8826204794314169398", - "host": [ - "{{host}}" - ], - "path": [ - "v1", - "block", - "GetBlock" - ], - "query": [ - { - "key": "ID", - "value": "-8826204794314169398" - }, - { - "key": "Height", - "value": "20", - "disabled": true - }, - { - "key": "Chaintype", - "value": "0", - "disabled": true - } - ] - } - }, - "response": [] - } - ] - } - ] + "info": { + "_postman_id": "e8cb55b1-5c13-4894-8106-52f4bf019eee", + "name": "ZooBC", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "blocks", + "item": [ + { + "name": "GetBlocks", + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{host}}/v1/block/GetBlocks?Limit=10&Height=0&Chaintype=0", + "host": [ + "{{host}}" + ], + "path": [ + "v1", + "block", + "GetBlocks" + ], + "query": [ + { + "key": "Limit", + "value": "10" + }, + { + "key": "Height", + "value": "0" + }, + { + "key": "Chaintype", + "value": "0" + } + ] + } + }, + "response": [] + }, + { + "name": "GetBlock", + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{host}}/v1/block/GetBlock?ID=-8826204794314169398", + "host": [ + "{{host}}" + ], + "path": [ + "v1", + "block", + "GetBlock" + ], + "query": [ + { + "key": "ID", + "value": "-8826204794314169398" + }, + { + "key": "Height", + "value": "20", + "disabled": true + }, + { + "key": "Chaintype", + "value": "0", + "disabled": true + } + ] + } + }, + "response": [] + } + ] + } + ] } \ No newline at end of file diff --git a/api/handler/nodeHardwareHandler.go b/api/handler/nodeHardwareHandler.go index 8594f93b0..001173a5e 100644 --- a/api/handler/nodeHardwareHandler.go +++ b/api/handler/nodeHardwareHandler.go @@ -2,7 +2,6 @@ package handler import ( "io" - "time" "github.com/zoobc/zoobc-core/api/service" diff --git a/common/constant/participationScore.go b/common/constant/participationScore.go index d27c02772..4c064280b 100644 --- a/common/constant/participationScore.go +++ b/common/constant/participationScore.go @@ -3,9 +3,9 @@ package constant const ( // ScalarReceiptScore the converter score to avoid calculation in float number ScalarReceiptScore float32 = 1000000 - // LinkedReceiptScore the score for each receipt that proved have relation with prevoius published receipt via merkle root + // LinkedReceiptScore the score for each receipt that proved have relation with previous published receipt via merkle root LinkedReceiptScore float32 = 2 - // LinkedReceiptScore the score for each receipt that can't proved have relation with prevoius published receipt via merkle root + // LinkedReceiptScore the score for each receipt that can't proved have relation with previous published receipt via merkle root UnlinkedReceiptScore float32 = 0.5 // MaxScoreChange the maximum score that node wll get MaxScoreChange int64 = 10 * int64(ScalarReceiptScore) diff --git a/common/constant/receipt.go b/common/constant/receipt.go index 031480142..c8cda49ee 100644 --- a/common/constant/receipt.go +++ b/common/constant/receipt.go @@ -3,4 +3,5 @@ package constant const ( ReceiptDatumTypeBlock = uint32(1) ReceiptDatumTypeTransaction = uint32(2) + ReceiptBatchMaximum = uint32(8) // 256 in production ) diff --git a/common/database/migration.go b/common/database/migration.go index cc2bb7245..2cec9e754 100644 --- a/common/database/migration.go +++ b/common/database/migration.go @@ -3,7 +3,6 @@ package database import ( "fmt" - log "github.com/sirupsen/logrus" "github.com/zoobc/zoobc-core/common/query" ) @@ -27,11 +26,9 @@ and initialize versions func (m *Migration) Init() error { if m.Query != nil { - rows, _ := m.Query.ExecuteSelect("SELECT version FROM migration;", false) - if rows != nil { - defer rows.Close() - var version int - _ = rows.Scan(&version) + var version int + err := m.Query.ExecuteSelectRow("SELECT version FROM migration;").Scan(&version) + if err == nil { m.CurrentVersion = &version } @@ -135,16 +132,36 @@ func (m *Migration) Init() error { );`, ` CREATE TABLE IF NOT EXISTS "node_receipt" ( - "sender_public_key" BLOB, + "sender_public_key" BLOB, "recipient_public_key" BLOB, "datum_type" INTEGER, "datum_hash" BLOB, "reference_block_height" INTEGER, "reference_block_hash" BLOB, - "receipt_merkle_root" BLOB, + "rmr_linked" BLOB, + "recipient_signature" BLOB, + "rmr" BLOB, + "rmr_index" INTEGER + ) + `, + ` + CREATE TABLE IF NOT EXISTS "batch_receipt" ( + "sender_public_key" BLOB, + "recipient_public_key" BLOB, + "datum_type" INTEGER, + "datum_hash" BLOB, + "reference_block_height" INTEGER, + "reference_block_hash" BLOB, + "rmr_linked" BLOB, "recipient_signature" BLOB ) `, + ` + CREATE TABLE IF NOT EXISTS "merkle_tree" ( + "id" BLOB, + "tree" BLOB + ) + `, } return nil } @@ -160,29 +177,25 @@ func (m *Migration) Apply() error { var ( migrations = m.Versions + err error ) if m.CurrentVersion != nil { - migrations = m.Versions[*m.CurrentVersion:] + migrations = m.Versions[*m.CurrentVersion+1:] } - for version, query := range migrations { - var err error - version := version - err = m.Query.BeginTx() - if err != nil { - log.Warn(err) - } + for v, query := range migrations { + version := v + _ = m.Query.BeginTx() err = m.Query.ExecuteTransaction(query) if err != nil { - log.Warn(err) + return err } - if m.CurrentVersion != nil { err = m.Query.ExecuteTransaction(`UPDATE "migration" - SET "version" = ?, "created_date" = datetime('now');`, *m.CurrentVersion) + SET "version" = ?, "created_date" = datetime('now');`, *m.CurrentVersion+1) if err != nil { - log.Warn(err) + return err } } else { err = m.Query.ExecuteTransaction(` @@ -194,13 +207,14 @@ func (m *Migration) Apply() error { 0, datetime('now') ); - `) + `) if err != nil { - log.Warn(err) + return err } } - err = m.Query.CommitTx() + m.CurrentVersion = &version + err := m.Query.CommitTx() if err != nil { return err } diff --git a/common/database/migration_test.go b/common/database/migration_test.go index 4e5817d7b..a63bea56d 100644 --- a/common/database/migration_test.go +++ b/common/database/migration_test.go @@ -15,11 +15,23 @@ type ( } ) +func (*mockExecutorInitFailRows) ExecuteSelectRow(qe string, args ...interface{}) *sql.Row { + + db, mock, _ := sqlmock.New() + defer db.Close() + + mock.ExpectQuery(qe).WillReturnRows( + sqlmock.NewRows([]string{"count"}), + ) + return db.QueryRow(qe) +} + func (*mockExecutorInitFailRows) ExecuteSelect(qe string, tx bool, args ...interface{}) (*sql.Rows, error) { db, mock, _ := sqlmock.New() defer db.Close() mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ - "Version"}).AddRow(1)) + "Version", + }).AddRow(1)) rows, _ := db.Query(qe) return rows, nil @@ -97,46 +109,31 @@ func TestMigration_Init(t *testing.T) { var dbMock, mock, _ = sqlmock.New() type ( - mockQueryExecutorVersionNotNil struct { + mockQueryExecutorVersionNil struct { query.Executor } ) -func (*mockQueryExecutorVersionNotNil) ExecuteTransaction(qStr string, args ...interface{}) error { - db, mock, err := sqlmock.New() +func (*mockQueryExecutorVersionNil) BeginTx() error { + return nil +} +func (*mockQueryExecutorVersionNil) ExecuteTransaction(qStr string, args ...interface{}) error { + db, mock, _ := sqlmock.New() + defer db.Close() + + mock.ExpectPrepare(regexp.QuoteMeta(qStr)).ExpectExec().WillReturnResult(sqlmock.NewResult(1, 1)) + stmt, err := db.Prepare(qStr) if err != nil { return err } - - mock.ExpectBegin() - mock.ExpectPrepare(regexp.QuoteMeta(` - CREATE TABLE IF NOT EXISTS "accounts" ( - id INTEGER, - public_key BLOB NOT NULL, - PRIMARY KEY("public_key") - ); - `)).ExpectExec().WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectPrepare(regexp.QuoteMeta(` - INSERT INTO "migration" ( - "version", - "created_date" - ) - VALUES ( - 0, - datetime('now') - ); - `)).ExpectExec().WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectCommit() - _, err = db.Exec("") + _, err = stmt.Exec(args...) return err } - -func (*mockQueryExecutorVersionNotNil) CommitTx() error { +func (*mockQueryExecutorVersionNil) CommitTx() error { return nil } - func TestMigration_Apply(t *testing.T) { - currentVersion := 0 + currentVersion := 1 type fields struct { CurrentVersion *int @@ -157,8 +154,14 @@ func TestMigration_Apply(t *testing.T) { public_key BLOB NOT NULL, PRIMARY KEY("public_key") );`, + `CREATE TABLE IF NOT EXISTS "accounts" ( + id INTEGER, + public_key BLOB NOT NULL, + PRIMARY KEY("public_key") + );`, }, - Query: &mockQueryExecutorVersionNotNil{ + CurrentVersion: ¤tVersion, + Query: &mockQueryExecutorVersionNil{ query.Executor{Db: dbMock}, }, }, @@ -167,15 +170,15 @@ func TestMigration_Apply(t *testing.T) { { name: "wantSuccess:VersionNil", fields: fields{ - CurrentVersion: ¤tVersion, + CurrentVersion: nil, Versions: []string{ - `CREATE TABLE IF NOT EXISTS "accounts" ( + `CREATE TABLE IF NOT EXISTS "account" ( id INTEGER, public_key BLOB NOT NULL, PRIMARY KEY("public_key") );`, }, - Query: &mockQueryExecutorVersionNotNil{ + Query: &mockQueryExecutorVersionNil{ query.Executor{Db: dbMock}, }, }, @@ -190,11 +193,11 @@ func TestMigration_Apply(t *testing.T) { Query: tt.fields.Query, } if err := m.Apply(); (err != nil) != tt.wantErr { - t.Errorf("Migration.Apply() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("Migration.Apply() error = \n%v, wantErr \n%v", err, tt.wantErr) return } if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("Migration.Apply() query: %s, want: %s", tt.fields.Versions[0], err) + t.Errorf("Migration.Apply() query: \n%s, want: \n%s", tt.fields.Versions[0], err) } }) } diff --git a/common/interceptor/interceptor.go b/common/interceptor/interceptor.go index c82e6cdd5..8e3459902 100644 --- a/common/interceptor/interceptor.go +++ b/common/interceptor/interceptor.go @@ -6,14 +6,12 @@ import ( "runtime" "time" + "github.com/sirupsen/logrus" "github.com/zoobc/zoobc-core/common/blocker" "github.com/zoobc/zoobc-core/common/crypto" "github.com/zoobc/zoobc-core/common/model" - "google.golang.org/grpc/metadata" - - "github.com/sirupsen/logrus" - "google.golang.org/grpc" + "google.golang.org/grpc/metadata" ) /* diff --git a/common/model/batchReceipt.pb.go b/common/model/batchReceipt.pb.go new file mode 100644 index 000000000..92ed7d5eb --- /dev/null +++ b/common/model/batchReceipt.pb.go @@ -0,0 +1,142 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: model/batchReceipt.proto + +package model + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type BatchReceipt struct { + SenderPublicKey []byte `protobuf:"bytes,1,opt,name=SenderPublicKey,proto3" json:"SenderPublicKey,omitempty"` + RecipientPublicKey []byte `protobuf:"bytes,2,opt,name=RecipientPublicKey,proto3" json:"RecipientPublicKey,omitempty"` + DatumType uint32 `protobuf:"varint,3,opt,name=DatumType,proto3" json:"DatumType,omitempty"` + DatumHash []byte `protobuf:"bytes,4,opt,name=DatumHash,proto3" json:"DatumHash,omitempty"` + ReferenceBlockHeight uint32 `protobuf:"varint,5,opt,name=ReferenceBlockHeight,proto3" json:"ReferenceBlockHeight,omitempty"` + ReferenceBlockHash []byte `protobuf:"bytes,6,opt,name=ReferenceBlockHash,proto3" json:"ReferenceBlockHash,omitempty"` + RMRLinked []byte `protobuf:"bytes,7,opt,name=RMRLinked,proto3" json:"RMRLinked,omitempty"` + RecipientSignature []byte `protobuf:"bytes,8,opt,name=RecipientSignature,proto3" json:"RecipientSignature,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BatchReceipt) Reset() { *m = BatchReceipt{} } +func (m *BatchReceipt) String() string { return proto.CompactTextString(m) } +func (*BatchReceipt) ProtoMessage() {} +func (*BatchReceipt) Descriptor() ([]byte, []int) { + return fileDescriptor_f3d73f8c2557fbad, []int{0} +} + +func (m *BatchReceipt) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BatchReceipt.Unmarshal(m, b) +} +func (m *BatchReceipt) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BatchReceipt.Marshal(b, m, deterministic) +} +func (m *BatchReceipt) XXX_Merge(src proto.Message) { + xxx_messageInfo_BatchReceipt.Merge(m, src) +} +func (m *BatchReceipt) XXX_Size() int { + return xxx_messageInfo_BatchReceipt.Size(m) +} +func (m *BatchReceipt) XXX_DiscardUnknown() { + xxx_messageInfo_BatchReceipt.DiscardUnknown(m) +} + +var xxx_messageInfo_BatchReceipt proto.InternalMessageInfo + +func (m *BatchReceipt) GetSenderPublicKey() []byte { + if m != nil { + return m.SenderPublicKey + } + return nil +} + +func (m *BatchReceipt) GetRecipientPublicKey() []byte { + if m != nil { + return m.RecipientPublicKey + } + return nil +} + +func (m *BatchReceipt) GetDatumType() uint32 { + if m != nil { + return m.DatumType + } + return 0 +} + +func (m *BatchReceipt) GetDatumHash() []byte { + if m != nil { + return m.DatumHash + } + return nil +} + +func (m *BatchReceipt) GetReferenceBlockHeight() uint32 { + if m != nil { + return m.ReferenceBlockHeight + } + return 0 +} + +func (m *BatchReceipt) GetReferenceBlockHash() []byte { + if m != nil { + return m.ReferenceBlockHash + } + return nil +} + +func (m *BatchReceipt) GetRMRLinked() []byte { + if m != nil { + return m.RMRLinked + } + return nil +} + +func (m *BatchReceipt) GetRecipientSignature() []byte { + if m != nil { + return m.RecipientSignature + } + return nil +} + +func init() { + proto.RegisterType((*BatchReceipt)(nil), "model.BatchReceipt") +} + +func init() { proto.RegisterFile("model/batchReceipt.proto", fileDescriptor_f3d73f8c2557fbad) } + +var fileDescriptor_f3d73f8c2557fbad = []byte{ + // 255 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4a, 0xc3, 0x40, + 0x10, 0x86, 0x49, 0xb5, 0x55, 0x97, 0x8a, 0xb0, 0x78, 0xd8, 0x83, 0x87, 0xe2, 0x29, 0x08, 0x26, + 0xa0, 0x6f, 0x10, 0x3c, 0x14, 0x54, 0x90, 0xad, 0x27, 0x6f, 0xd9, 0xc9, 0x98, 0x2c, 0xcd, 0xee, + 0x84, 0x75, 0xf7, 0x50, 0x1f, 0xd4, 0xe7, 0x91, 0x6e, 0x30, 0xb1, 0xa1, 0x97, 0x39, 0x7c, 0xdf, + 0xf0, 0xf3, 0x0f, 0xc3, 0x84, 0xa1, 0x0a, 0xdb, 0x5c, 0x95, 0x1e, 0x1a, 0x89, 0x80, 0xba, 0xf3, + 0x59, 0xe7, 0xc8, 0x13, 0x9f, 0x47, 0x73, 0xfb, 0x33, 0x63, 0xcb, 0xe2, 0x9f, 0xe5, 0x29, 0xbb, + 0xda, 0xa0, 0xad, 0xd0, 0xbd, 0x05, 0xd5, 0x6a, 0x78, 0xc6, 0x9d, 0x48, 0x56, 0x49, 0xba, 0x94, + 0x53, 0xcc, 0x33, 0xc6, 0x25, 0x82, 0xee, 0x34, 0x5a, 0x3f, 0x2e, 0xcf, 0xe2, 0xf2, 0x11, 0xc3, + 0x6f, 0xd8, 0xc5, 0x53, 0xe9, 0x83, 0x79, 0xdf, 0x75, 0x28, 0x4e, 0x56, 0x49, 0x7a, 0x29, 0x47, + 0x30, 0xd8, 0x75, 0xf9, 0xd5, 0x88, 0xd3, 0x18, 0x32, 0x02, 0xfe, 0xc0, 0xae, 0x25, 0x7e, 0xa2, + 0x43, 0x0b, 0x58, 0xb4, 0x04, 0xdb, 0x35, 0xea, 0xba, 0xf1, 0x62, 0x1e, 0x63, 0x8e, 0xba, 0xbe, + 0xdf, 0x01, 0xdf, 0x47, 0x2f, 0xfe, 0xfa, 0x4d, 0xcd, 0xbe, 0x81, 0x7c, 0x95, 0x2f, 0xda, 0x6e, + 0xb1, 0x12, 0x67, 0x7d, 0x83, 0x01, 0x1c, 0x5c, 0xbb, 0xd1, 0xb5, 0x2d, 0x7d, 0x70, 0x28, 0xce, + 0x27, 0xd7, 0x0e, 0xa6, 0xb8, 0xfb, 0x48, 0x6b, 0xed, 0x9b, 0xa0, 0x32, 0x20, 0x93, 0x7f, 0x13, + 0x29, 0xe8, 0xe7, 0x3d, 0x90, 0xc3, 0x1c, 0xc8, 0x18, 0xb2, 0x79, 0x7c, 0x82, 0x5a, 0xc4, 0x97, + 0x3c, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x42, 0xc3, 0x49, 0x71, 0xae, 0x01, 0x00, 0x00, +} diff --git a/common/model/block.pb.go b/common/model/block.pb.go index bdd8d6f5a..d63b2c250 100644 --- a/common/model/block.pb.go +++ b/common/model/block.pb.go @@ -1,11 +1,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: model/block.proto -package model // import "github.com/zoobc/zoobc-core/common/model" +package model -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal @@ -16,7 +18,7 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Block represent the block data structure stored in the database type Block struct { @@ -46,16 +48,17 @@ func (m *Block) Reset() { *m = Block{} } func (m *Block) String() string { return proto.CompactTextString(m) } func (*Block) ProtoMessage() {} func (*Block) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{0} + return fileDescriptor_baa78346dbb08dbe, []int{0} } + func (m *Block) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Block.Unmarshal(m, b) } func (m *Block) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Block.Marshal(b, m, deterministic) } -func (dst *Block) XXX_Merge(src proto.Message) { - xxx_messageInfo_Block.Merge(dst, src) +func (m *Block) XXX_Merge(src proto.Message) { + xxx_messageInfo_Block.Merge(m, src) } func (m *Block) XXX_Size() int { return xxx_messageInfo_Block.Size(m) @@ -197,16 +200,17 @@ func (m *BlockReceipt) Reset() { *m = BlockReceipt{} } func (m *BlockReceipt) String() string { return proto.CompactTextString(m) } func (*BlockReceipt) ProtoMessage() {} func (*BlockReceipt) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{1} + return fileDescriptor_baa78346dbb08dbe, []int{1} } + func (m *BlockReceipt) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BlockReceipt.Unmarshal(m, b) } func (m *BlockReceipt) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_BlockReceipt.Marshal(b, m, deterministic) } -func (dst *BlockReceipt) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlockReceipt.Merge(dst, src) +func (m *BlockReceipt) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockReceipt.Merge(m, src) } func (m *BlockReceipt) XXX_Size() int { return xxx_messageInfo_BlockReceipt.Size(m) @@ -247,16 +251,17 @@ func (m *BlockExtendedInfo) Reset() { *m = BlockExtendedInfo{} } func (m *BlockExtendedInfo) String() string { return proto.CompactTextString(m) } func (*BlockExtendedInfo) ProtoMessage() {} func (*BlockExtendedInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{2} + return fileDescriptor_baa78346dbb08dbe, []int{2} } + func (m *BlockExtendedInfo) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BlockExtendedInfo.Unmarshal(m, b) } func (m *BlockExtendedInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_BlockExtendedInfo.Marshal(b, m, deterministic) } -func (dst *BlockExtendedInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlockExtendedInfo.Merge(dst, src) +func (m *BlockExtendedInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockExtendedInfo.Merge(m, src) } func (m *BlockExtendedInfo) XXX_Size() int { return xxx_messageInfo_BlockExtendedInfo.Size(m) @@ -319,16 +324,17 @@ func (m *GetBlockRequest) Reset() { *m = GetBlockRequest{} } func (m *GetBlockRequest) String() string { return proto.CompactTextString(m) } func (*GetBlockRequest) ProtoMessage() {} func (*GetBlockRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{3} + return fileDescriptor_baa78346dbb08dbe, []int{3} } + func (m *GetBlockRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetBlockRequest.Unmarshal(m, b) } func (m *GetBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_GetBlockRequest.Marshal(b, m, deterministic) } -func (dst *GetBlockRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetBlockRequest.Merge(dst, src) +func (m *GetBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBlockRequest.Merge(m, src) } func (m *GetBlockRequest) XXX_Size() int { return xxx_messageInfo_GetBlockRequest.Size(m) @@ -377,16 +383,17 @@ func (m *GetBlocksRequest) Reset() { *m = GetBlocksRequest{} } func (m *GetBlocksRequest) String() string { return proto.CompactTextString(m) } func (*GetBlocksRequest) ProtoMessage() {} func (*GetBlocksRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{4} + return fileDescriptor_baa78346dbb08dbe, []int{4} } + func (m *GetBlocksRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetBlocksRequest.Unmarshal(m, b) } func (m *GetBlocksRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_GetBlocksRequest.Marshal(b, m, deterministic) } -func (dst *GetBlocksRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetBlocksRequest.Merge(dst, src) +func (m *GetBlocksRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBlocksRequest.Merge(m, src) } func (m *GetBlocksRequest) XXX_Size() int { return xxx_messageInfo_GetBlocksRequest.Size(m) @@ -436,16 +443,17 @@ func (m *GetBlocksResponse) Reset() { *m = GetBlocksResponse{} } func (m *GetBlocksResponse) String() string { return proto.CompactTextString(m) } func (*GetBlocksResponse) ProtoMessage() {} func (*GetBlocksResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{5} + return fileDescriptor_baa78346dbb08dbe, []int{5} } + func (m *GetBlocksResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetBlocksResponse.Unmarshal(m, b) } func (m *GetBlocksResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_GetBlocksResponse.Marshal(b, m, deterministic) } -func (dst *GetBlocksResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetBlocksResponse.Merge(dst, src) +func (m *GetBlocksResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBlocksResponse.Merge(m, src) } func (m *GetBlocksResponse) XXX_Size() int { return xxx_messageInfo_GetBlocksResponse.Size(m) @@ -498,16 +506,17 @@ func (m *GetNextBlockIdsRequest) Reset() { *m = GetNextBlockIdsRequest{} func (m *GetNextBlockIdsRequest) String() string { return proto.CompactTextString(m) } func (*GetNextBlockIdsRequest) ProtoMessage() {} func (*GetNextBlockIdsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{6} + return fileDescriptor_baa78346dbb08dbe, []int{6} } + func (m *GetNextBlockIdsRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetNextBlockIdsRequest.Unmarshal(m, b) } func (m *GetNextBlockIdsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_GetNextBlockIdsRequest.Marshal(b, m, deterministic) } -func (dst *GetNextBlockIdsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetNextBlockIdsRequest.Merge(dst, src) +func (m *GetNextBlockIdsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetNextBlockIdsRequest.Merge(m, src) } func (m *GetNextBlockIdsRequest) XXX_Size() int { return xxx_messageInfo_GetNextBlockIdsRequest.Size(m) @@ -550,16 +559,17 @@ func (m *BlockIdsResponse) Reset() { *m = BlockIdsResponse{} } func (m *BlockIdsResponse) String() string { return proto.CompactTextString(m) } func (*BlockIdsResponse) ProtoMessage() {} func (*BlockIdsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{7} + return fileDescriptor_baa78346dbb08dbe, []int{7} } + func (m *BlockIdsResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BlockIdsResponse.Unmarshal(m, b) } func (m *BlockIdsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_BlockIdsResponse.Marshal(b, m, deterministic) } -func (dst *BlockIdsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlockIdsResponse.Merge(dst, src) +func (m *BlockIdsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockIdsResponse.Merge(m, src) } func (m *BlockIdsResponse) XXX_Size() int { return xxx_messageInfo_BlockIdsResponse.Size(m) @@ -591,16 +601,17 @@ func (m *GetNextBlocksRequest) Reset() { *m = GetNextBlocksRequest{} } func (m *GetNextBlocksRequest) String() string { return proto.CompactTextString(m) } func (*GetNextBlocksRequest) ProtoMessage() {} func (*GetNextBlocksRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{8} + return fileDescriptor_baa78346dbb08dbe, []int{8} } + func (m *GetNextBlocksRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetNextBlocksRequest.Unmarshal(m, b) } func (m *GetNextBlocksRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_GetNextBlocksRequest.Marshal(b, m, deterministic) } -func (dst *GetNextBlocksRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetNextBlocksRequest.Merge(dst, src) +func (m *GetNextBlocksRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetNextBlocksRequest.Merge(m, src) } func (m *GetNextBlocksRequest) XXX_Size() int { return xxx_messageInfo_GetNextBlocksRequest.Size(m) @@ -643,16 +654,17 @@ func (m *BlocksData) Reset() { *m = BlocksData{} } func (m *BlocksData) String() string { return proto.CompactTextString(m) } func (*BlocksData) ProtoMessage() {} func (*BlocksData) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{9} + return fileDescriptor_baa78346dbb08dbe, []int{9} } + func (m *BlocksData) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BlocksData.Unmarshal(m, b) } func (m *BlocksData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_BlocksData.Marshal(b, m, deterministic) } -func (dst *BlocksData) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlocksData.Merge(dst, src) +func (m *BlocksData) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlocksData.Merge(m, src) } func (m *BlocksData) XXX_Size() int { return xxx_messageInfo_BlocksData.Size(m) @@ -683,16 +695,17 @@ func (m *SendBlockRequest) Reset() { *m = SendBlockRequest{} } func (m *SendBlockRequest) String() string { return proto.CompactTextString(m) } func (*SendBlockRequest) ProtoMessage() {} func (*SendBlockRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_block_27040aed85a8bc82, []int{10} + return fileDescriptor_baa78346dbb08dbe, []int{10} } + func (m *SendBlockRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SendBlockRequest.Unmarshal(m, b) } func (m *SendBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_SendBlockRequest.Marshal(b, m, deterministic) } -func (dst *SendBlockRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_SendBlockRequest.Merge(dst, src) +func (m *SendBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SendBlockRequest.Merge(m, src) } func (m *SendBlockRequest) XXX_Size() int { return xxx_messageInfo_SendBlockRequest.Size(m) @@ -724,6 +737,45 @@ func (m *SendBlockRequest) GetSenderPublicKey() []byte { return nil } +type SendBlockResponse struct { + BatchReceipt *BatchReceipt `protobuf:"bytes,1,opt,name=BatchReceipt,proto3" json:"BatchReceipt,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SendBlockResponse) Reset() { *m = SendBlockResponse{} } +func (m *SendBlockResponse) String() string { return proto.CompactTextString(m) } +func (*SendBlockResponse) ProtoMessage() {} +func (*SendBlockResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_baa78346dbb08dbe, []int{11} +} + +func (m *SendBlockResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SendBlockResponse.Unmarshal(m, b) +} +func (m *SendBlockResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SendBlockResponse.Marshal(b, m, deterministic) +} +func (m *SendBlockResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SendBlockResponse.Merge(m, src) +} +func (m *SendBlockResponse) XXX_Size() int { + return xxx_messageInfo_SendBlockResponse.Size(m) +} +func (m *SendBlockResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SendBlockResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SendBlockResponse proto.InternalMessageInfo + +func (m *SendBlockResponse) GetBatchReceipt() *BatchReceipt { + if m != nil { + return m.BatchReceipt + } + return nil +} + func init() { proto.RegisterType((*Block)(nil), "model.Block") proto.RegisterType((*BlockReceipt)(nil), "model.BlockReceipt") @@ -736,60 +788,62 @@ func init() { proto.RegisterType((*GetNextBlocksRequest)(nil), "model.GetNextBlocksRequest") proto.RegisterType((*BlocksData)(nil), "model.BlocksData") proto.RegisterType((*SendBlockRequest)(nil), "model.SendBlockRequest") -} - -func init() { proto.RegisterFile("model/block.proto", fileDescriptor_block_27040aed85a8bc82) } - -var fileDescriptor_block_27040aed85a8bc82 = []byte{ - // 786 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x5d, 0x6b, 0xe3, 0x46, - 0x14, 0x45, 0xd2, 0x3a, 0x89, 0xaf, 0xed, 0x24, 0x9e, 0x84, 0xed, 0xb0, 0x2c, 0x8b, 0x10, 0xcb, - 0x22, 0xca, 0xd6, 0x09, 0x29, 0x14, 0xba, 0x6f, 0x89, 0xd3, 0xee, 0x9a, 0x2e, 0x25, 0x28, 0x66, - 0x1f, 0x5a, 0x28, 0x8c, 0xa5, 0x1b, 0x6b, 0x5a, 0x49, 0xe3, 0x6a, 0x46, 0xcb, 0xba, 0x0f, 0xfd, - 0x0f, 0x7d, 0xeb, 0x3f, 0xec, 0xdf, 0x28, 0x1e, 0x8d, 0xbe, 0x5c, 0x9b, 0xe6, 0x61, 0x5f, 0x8c, - 0xe6, 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 0xbf, 0xc2, 0xd3, 0xb7, 0xa8, 0x7e, 0xc4, 0x4f, 0x65, 0x59, - 0xb3, 0xe8, 0x91, 0x9d, 0x3f, 0x87, 0x43, 0xb3, 0xa1, 0x75, 0xb8, 0x15, 0xd4, 0x9c, 0x8b, 0xd3, - 0x3a, 0x17, 0xef, 0x0a, 0x4e, 0x1b, 0x11, 0xd3, 0xfd, 0x0b, 0x38, 0xaa, 0x30, 0x6a, 0xb9, 0x4e, - 0xf5, 0x86, 0x54, 0x98, 0x97, 0xc3, 0x79, 0xbb, 0xbe, 0xcf, 0x52, 0x5d, 0x5b, 0xd3, 0xd9, 0xa1, - 0xf9, 0x06, 0xa0, 0x14, 0xbb, 0x65, 0x8a, 0x91, 0xd7, 0x00, 0x8d, 0xbc, 0xae, 0x71, 0xdb, 0x4b, - 0x2d, 0xde, 0xfb, 0x13, 0x4e, 0xef, 0x31, 0x8b, 0x3a, 0x13, 0xfa, 0x18, 0x23, 0x76, 0xfa, 0xb1, - 0xb7, 0xfb, 0xf1, 0xe1, 0x64, 0x93, 0x15, 0xf3, 0xe6, 0xf5, 0x76, 0xf4, 0x1b, 0xb7, 0x0d, 0xdf, - 0x7c, 0xf9, 0x93, 0xbf, 0xe4, 0x2a, 0x2e, 0x16, 0x93, 0x50, 0xa4, 0x17, 0x7f, 0x08, 0xb1, 0x08, - 0xcb, 0xdf, 0xaf, 0x42, 0x91, 0xe3, 0x45, 0x28, 0xd2, 0x54, 0x64, 0x17, 0xba, 0x80, 0xc5, 0x81, - 0xfe, 0x0b, 0xfd, 0xfa, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf1, 0xb2, 0x04, 0x6f, 0x8c, 0x07, - 0x00, 0x00, + proto.RegisterType((*SendBlockResponse)(nil), "model.SendBlockResponse") +} + +func init() { proto.RegisterFile("model/block.proto", fileDescriptor_baa78346dbb08dbe) } + +var fileDescriptor_baa78346dbb08dbe = []byte{ + // 814 bytes of a gzipped FileDescriptorProto + 0x1f, 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 0xdb, 0xf9, 0x04, 0x70, 0xb0, 0xf1, 0x8a, 0x45, 0xbb, + 0xbd, 0xfb, 0x7a, 0xc7, 0x6d, 0xc3, 0xfe, 0x25, 0x4c, 0x2c, 0x7d, 0x53, 0xe4, 0xaf, 0xc1, 0x9d, + 0x59, 0xff, 0xa7, 0x26, 0x8e, 0x66, 0x87, 0x59, 0x54, 0xd8, 0x31, 0x9c, 0x7d, 0xfe, 0x63, 0xb0, + 0xe2, 0x2a, 0x29, 0x97, 0xd3, 0x48, 0x64, 0x27, 0xbf, 0x0b, 0xb1, 0x8c, 0xaa, 0xdf, 0x2f, 0x22, + 0x51, 0xe0, 0x49, 0x24, 0xb2, 0x4c, 0xe4, 0x27, 0xda, 0xcd, 0x72, 0x47, 0xff, 0x21, 0x7f, 0xf9, + 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x62, 0x63, 0x8c, 0x5e, 0xf4, 0x07, 0x00, 0x00, } diff --git a/common/model/receipt.pb.go b/common/model/receipt.pb.go index 25729d637..d75a1f529 100644 --- a/common/model/receipt.pb.go +++ b/common/model/receipt.pb.go @@ -21,17 +21,12 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type Receipt struct { - SenderPublicKey []byte `protobuf:"bytes,1,opt,name=SenderPublicKey,proto3" json:"SenderPublicKey,omitempty"` - RecipientPublicKey []byte `protobuf:"bytes,2,opt,name=RecipientPublicKey,proto3" json:"RecipientPublicKey,omitempty"` - DatumType uint32 `protobuf:"varint,3,opt,name=DatumType,proto3" json:"DatumType,omitempty"` - DatumHash []byte `protobuf:"bytes,4,opt,name=DatumHash,proto3" json:"DatumHash,omitempty"` - ReferenceBlockHeight uint32 `protobuf:"varint,5,opt,name=ReferenceBlockHeight,proto3" json:"ReferenceBlockHeight,omitempty"` - ReferenceBlockHash []byte `protobuf:"bytes,6,opt,name=ReferenceBlockHash,proto3" json:"ReferenceBlockHash,omitempty"` - ReceiptMerkleRoot []byte `protobuf:"bytes,7,opt,name=ReceiptMerkleRoot,proto3" json:"ReceiptMerkleRoot,omitempty"` - RecipientSignature []byte `protobuf:"bytes,8,opt,name=RecipientSignature,proto3" json:"RecipientSignature,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + BatchReceipt *BatchReceipt `protobuf:"bytes,1,opt,name=batchReceipt,proto3" json:"batchReceipt,omitempty"` + RMR []byte `protobuf:"bytes,2,opt,name=RMR,proto3" json:"RMR,omitempty"` + RMRIndex uint32 `protobuf:"varint,3,opt,name=RMRIndex,proto3" json:"RMRIndex,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Receipt) Reset() { *m = Receipt{} } @@ -59,62 +54,27 @@ func (m *Receipt) XXX_DiscardUnknown() { var xxx_messageInfo_Receipt proto.InternalMessageInfo -func (m *Receipt) GetSenderPublicKey() []byte { +func (m *Receipt) GetBatchReceipt() *BatchReceipt { if m != nil { - return m.SenderPublicKey + return m.BatchReceipt } return nil } -func (m *Receipt) GetRecipientPublicKey() []byte { +func (m *Receipt) GetRMR() []byte { if m != nil { - return m.RecipientPublicKey + return m.RMR } return nil } -func (m *Receipt) GetDatumType() uint32 { +func (m *Receipt) GetRMRIndex() uint32 { if m != nil { - return m.DatumType + return m.RMRIndex } return 0 } -func (m *Receipt) GetDatumHash() []byte { - if m != nil { - return m.DatumHash - } - return nil -} - -func (m *Receipt) GetReferenceBlockHeight() uint32 { - if m != nil { - return m.ReferenceBlockHeight - } - return 0 -} - -func (m *Receipt) GetReferenceBlockHash() []byte { - if m != nil { - return m.ReferenceBlockHash - } - return nil -} - -func (m *Receipt) GetReceiptMerkleRoot() []byte { - if m != nil { - return m.ReceiptMerkleRoot - } - return nil -} - -func (m *Receipt) GetRecipientSignature() []byte { - if m != nil { - return m.RecipientSignature - } - return nil -} - func init() { proto.RegisterType((*Receipt)(nil), "model.Receipt") } @@ -122,21 +82,16 @@ func init() { func init() { proto.RegisterFile("model/receipt.proto", fileDescriptor_cb9bd5eefeeea3e5) } var fileDescriptor_cb9bd5eefeeea3e5 = []byte{ - // 256 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4a, 0xc3, 0x40, - 0x10, 0x86, 0x49, 0xb5, 0xad, 0x2e, 0x8a, 0xb8, 0x7a, 0xd8, 0x83, 0x87, 0xe2, 0x29, 0x88, 0x26, - 0xa0, 0x6f, 0x50, 0x3c, 0x14, 0x44, 0x90, 0xad, 0x27, 0x6f, 0xc9, 0xf4, 0x37, 0x59, 0x9a, 0xec, - 0x84, 0x75, 0x73, 0xa8, 0x6f, 0xeb, 0x9b, 0x88, 0x1b, 0x6d, 0x68, 0xec, 0x65, 0x0f, 0xdf, 0xf7, - 0xf3, 0x33, 0xb3, 0x23, 0x2e, 0x6a, 0x5e, 0xa1, 0x4a, 0x1d, 0x08, 0xa6, 0xf1, 0x49, 0xe3, 0xd8, - 0xb3, 0x1c, 0x07, 0x78, 0xfd, 0x35, 0x12, 0x53, 0xdd, 0x09, 0x19, 0x8b, 0xb3, 0x25, 0xec, 0x0a, - 0xee, 0xa5, 0xcd, 0x2b, 0x43, 0x4f, 0xd8, 0xa8, 0x68, 0x16, 0xc5, 0x27, 0x7a, 0x88, 0x65, 0x22, - 0xa4, 0x06, 0x99, 0xc6, 0xc0, 0xfa, 0x3e, 0x3c, 0x0a, 0xe1, 0x3d, 0x46, 0x5e, 0x89, 0xe3, 0xc7, - 0xcc, 0xb7, 0xf5, 0xeb, 0xa6, 0x81, 0x3a, 0x98, 0x45, 0xf1, 0xa9, 0xee, 0xc1, 0xd6, 0x2e, 0xb2, - 0x8f, 0x52, 0x1d, 0x86, 0x92, 0x1e, 0xc8, 0x7b, 0x71, 0xa9, 0xf1, 0x0e, 0x07, 0x4b, 0x98, 0x57, - 0x4c, 0xeb, 0x05, 0x4c, 0x51, 0x7a, 0x35, 0x0e, 0x35, 0x7b, 0x5d, 0x37, 0xdf, 0x0e, 0xff, 0xa9, - 0x9e, 0xfc, 0xcd, 0x37, 0x34, 0xf2, 0x56, 0x9c, 0xff, 0x7e, 0xc2, 0x33, 0xdc, 0xba, 0x82, 0x66, - 0xf6, 0x6a, 0x1a, 0xe2, 0xff, 0xc5, 0xce, 0xf6, 0x4b, 0x53, 0xd8, 0xcc, 0xb7, 0x0e, 0xea, 0x68, - 0xb0, 0xfd, 0xd6, 0xcc, 0x6f, 0xde, 0xe2, 0xc2, 0xf8, 0xb2, 0xcd, 0x13, 0xe2, 0x3a, 0xfd, 0x64, - 0xce, 0xa9, 0x7b, 0xef, 0x88, 0x1d, 0x52, 0xe2, 0xba, 0x66, 0x9b, 0x86, 0x7b, 0xe4, 0x93, 0x70, - 0x9d, 0x87, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x24, 0x44, 0x6d, 0x38, 0xb4, 0x01, 0x00, 0x00, + // 170 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xce, 0xcd, 0x4f, 0x49, + 0xcd, 0xd1, 0x2f, 0x4a, 0x4d, 0x4e, 0xcd, 0x2c, 0x28, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x62, 0x05, 0x0b, 0x4a, 0x49, 0x40, 0xe4, 0x92, 0x12, 0x4b, 0x92, 0x33, 0x82, 0x90, 0x15, 0x28, + 0x15, 0x70, 0xb1, 0x43, 0x05, 0x84, 0xcc, 0xb9, 0x78, 0x90, 0x15, 0x48, 0x30, 0x2a, 0x30, 0x6a, + 0x70, 0x1b, 0x09, 0xeb, 0x81, 0xf5, 0xea, 0x39, 0x21, 0x49, 0x05, 0xa1, 0x28, 0x14, 0x12, 0xe0, + 0x62, 0x0e, 0xf2, 0x0d, 0x92, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x09, 0x02, 0x31, 0x85, 0xa4, 0xb8, + 0x38, 0x82, 0x7c, 0x83, 0x3c, 0xf3, 0x52, 0x52, 0x2b, 0x24, 0x98, 0x15, 0x18, 0x35, 0x78, 0x83, + 0xe0, 0x7c, 0x27, 0xad, 0x28, 0x8d, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, + 0xfd, 0xaa, 0xfc, 0xfc, 0xa4, 0x64, 0x08, 0xa9, 0x9b, 0x9c, 0x5f, 0x94, 0xaa, 0x9f, 0x9c, 0x9f, + 0x9b, 0x9b, 0x9f, 0xa7, 0x0f, 0xb6, 0x34, 0x89, 0x0d, 0xec, 0x48, 0x63, 0x40, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x18, 0xc5, 0x58, 0x28, 0xdc, 0x00, 0x00, 0x00, } diff --git a/common/model/transaction.pb.go b/common/model/transaction.pb.go index 9f45d98eb..7b394740e 100644 --- a/common/model/transaction.pb.go +++ b/common/model/transaction.pb.go @@ -1108,6 +1108,45 @@ func (m *SendTransactionRequest) GetSenderPublicKey() []byte { return nil } +type SendTransactionResponse struct { + BatchReceipt *BatchReceipt `protobuf:"bytes,1,opt,name=BatchReceipt,proto3" json:"BatchReceipt,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SendTransactionResponse) Reset() { *m = SendTransactionResponse{} } +func (m *SendTransactionResponse) String() string { return proto.CompactTextString(m) } +func (*SendTransactionResponse) ProtoMessage() {} +func (*SendTransactionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8333001f09b34082, []int{15} +} + +func (m *SendTransactionResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SendTransactionResponse.Unmarshal(m, b) +} +func (m *SendTransactionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SendTransactionResponse.Marshal(b, m, deterministic) +} +func (m *SendTransactionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SendTransactionResponse.Merge(m, src) +} +func (m *SendTransactionResponse) XXX_Size() int { + return xxx_messageInfo_SendTransactionResponse.Size(m) +} +func (m *SendTransactionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SendTransactionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SendTransactionResponse proto.InternalMessageInfo + +func (m *SendTransactionResponse) GetBatchReceipt() *BatchReceipt { + if m != nil { + return m.BatchReceipt + } + return nil +} + func init() { proto.RegisterEnum("model.TransactionType", TransactionType_name, TransactionType_value) proto.RegisterType((*Transaction)(nil), "model.Transaction") @@ -1125,79 +1164,83 @@ func init() { proto.RegisterType((*PostTransactionRequest)(nil), "model.PostTransactionRequest") proto.RegisterType((*PostTransactionResponse)(nil), "model.PostTransactionResponse") proto.RegisterType((*SendTransactionRequest)(nil), "model.SendTransactionRequest") + proto.RegisterType((*SendTransactionResponse)(nil), "model.SendTransactionResponse") } func init() { proto.RegisterFile("model/transaction.proto", fileDescriptor_8333001f09b34082) } var fileDescriptor_8333001f09b34082 = []byte{ - // 1101 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x57, 0xdf, 0x6e, 0xdb, 0x54, - 0x18, 0x8f, 0x9d, 0x26, 0x6b, 0xbe, 0xa4, 0x9d, 0x7b, 0x48, 0x93, 0xa3, 0xae, 0x5a, 0x82, 0xd7, - 0x56, 0x21, 0x63, 0x2d, 0x84, 0x69, 0xe2, 0xb6, 0x59, 0x06, 0xa9, 0x58, 0x69, 0x70, 0xcb, 0x2e, - 0x90, 0xb8, 0x70, 0xed, 0xb3, 0xc4, 0x6a, 0xec, 0x63, 0xec, 0x13, 0x46, 0x40, 0x42, 0xa2, 0x70, - 0x83, 0xc4, 0x5b, 0xec, 0x59, 0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5d, 0x65, 0x24, 0x43, 0x19, 0xde, 0xe1, 0xa6, 0xdf, 0x0f, 0x4c, 0x7f, 0x99, 0x47, 0x66, - 0x58, 0x50, 0xf2, 0x29, 0xe7, 0x6e, 0x38, 0xc4, 0xa4, 0xdf, 0x66, 0xba, 0x81, 0x62, 0x6e, 0x28, - 0x79, 0x64, 0x3c, 0x37, 0x72, 0x29, 0x47, 0x3f, 0x09, 0x70, 0xa0, 0x4d, 0x55, 0xc3, 0xcc, 0xf2, - 0xe2, 0x1d, 0xee, 0xc5, 0xe3, 0xc0, 0x8b, 0xe7, 0x39, 0x44, 0x86, 0x05, 0x25, 0x97, 0x6a, 0xf4, - 0x03, 0xc8, 0x2e, 0x61, 0x33, 0x3b, 0x28, 0xf8, 0x81, 0xca, 0x54, 0x97, 0xb0, 0xa4, 0x03, 0x75, - 0xee, 0xc0, 0x7b, 0x61, 0xba, 0x65, 0x09, 0x0c, 0x0b, 0x4a, 0x0e, 0xb5, 0xe8, 0x47, 0x78, 0xe4, - 0x9f, 0xd4, 0x7a, 0xeb, 0xbb, 0xdc, 0x7a, 0x37, 0x76, 0x09, 0x59, 0xe6, 0xf3, 0x28, 0x46, 0xfb, - 0x50, 0xb9, 0x34, 0xc6, 0x96, 0xca, 0x66, 0x0e, 0xc1, 0x0d, 0xde, 0x09, 0x96, 0x40, 0x7f, 0x27, - 0xd6, 0x92, 0x3c, 0x01, 0xb9, 0x01, 0xf5, 0xb4, 0x12, 0x96, 0x9f, 0x01, 0xbe, 0xab, 0x06, 0xd1, - 0x1e, 0x94, 0x4f, 0x4d, 0xcf, 0x09, 0x3e, 0x0c, 0xfc, 0xc6, 0x17, 0x20, 0xf2, 0xdf, 0x02, 0xb4, - 0xb2, 0x6e, 0xe8, 0x00, 0xb6, 0x3c, 0x96, 0xd1, 0xec, 0x7a, 0x6a, 0x68, 0x9f, 0x91, 0x39, 0x57, - 0x53, 0x53, 0xe2, 0x20, 0x3a, 0x82, 0xed, 0x44, 0x4b, 0x17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 0x9d, 0x3f, 0x01, 0x77, 0xdf, 0x8a, 0x90, 0xf2, 0xd2, 0x90, - 0x92, 0xb3, 0x58, 0x2a, 0x20, 0xec, 0xbf, 0x8b, 0x92, 0x93, 0x58, 0x12, 0x50, 0x0b, 0x1e, 0xac, - 0xa9, 0x57, 0x49, 0x44, 0x47, 0xf0, 0x6e, 0xe6, 0x78, 0x92, 0x6e, 0x39, 0x5f, 0x66, 0xf3, 0x97, - 0x6e, 0x37, 0xd0, 0x21, 0xb4, 0xb3, 0xba, 0x84, 0x74, 0x5b, 0x46, 0x32, 0x3c, 0x5c, 0xdf, 0xfb, - 0xa5, 0x22, 0x3a, 0x80, 0x56, 0x46, 0xe3, 0x94, 0x7e, 0x16, 0xfb, 0xdd, 0xaf, 0x3a, 0x63, 0x83, - 0x4d, 0x66, 0xd7, 0xc7, 0x1a, 0x35, 0x4f, 0xbe, 0xa7, 0xf4, 0x5a, 0xf3, 0xbf, 0x4f, 0x34, 0xea, - 0x90, 0x13, 0x8d, 0x9a, 0x26, 0xb5, 0x4e, 0xf8, 0xcd, 0x5f, 0x97, 0xf9, 0xd3, 0xf5, 0xa3, 0x7f, - 0x02, 0x00, 0x00, 0xff, 0xff, 0xec, 0x8a, 0x4e, 0xeb, 0x12, 0x0f, 0x00, 0x00, + // 1138 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x57, 0xdb, 0x6e, 0xe3, 0x44, + 0x18, 0x8e, 0x9d, 0xa6, 0x87, 0x3f, 0x69, 0xd7, 0x9d, 0x4d, 0x93, 0x51, 0xb7, 0xda, 0x06, 0x6f, + 0x5b, 0x85, 0x2e, 0xdb, 0x42, 0x59, 0x2d, 0xdc, 0x36, 0xdb, 0x85, 0x54, 0x6c, 0x69, 0x98, 0x96, + 0xbd, 0x40, 0xe2, 0xc2, 0xb1, 0x67, 0x13, 0xab, 0xb1, 0xc7, 0xd8, 0x13, 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9d, 0x5f, 0xfe, 0x80, 0x7d, + 0x3e, 0xd4, 0xcc, 0xe0, 0x86, 0xfc, 0xb4, 0xa8, 0x90, 0x19, 0xe0, 0xdf, 0x62, 0xf0, 0x4e, 0x99, + 0x15, 0x48, 0x39, 0xd8, 0xf9, 0x53, 0xb0, 0x4a, 0xa0, 0x39, 0xe7, 0x4d, 0x18, 0xdf, 0x47, 0x50, + 0xeb, 0xc4, 0x9e, 0x64, 0x61, 0x80, 0xf7, 0xc3, 0x00, 0xe3, 0x24, 0x92, 0x60, 0x3c, 0x7c, 0x2b, + 0x43, 0xc6, 0xeb, 0x45, 0x49, 0xcf, 0x77, 0xa5, 0x84, 0x70, 0xf0, 0xd6, 0x4a, 0x4f, 0x77, 0x45, + 0x42, 0xbb, 0xf0, 0x60, 0x41, 0x0f, 0x50, 0x64, 0x74, 0x00, 0xef, 0xe4, 0x8e, 0x3c, 0xe5, 0x56, + 0xf0, 0xe5, 0x0e, 0x14, 0xe5, 0x76, 0x09, 0xed, 0x43, 0x2b, 0xaf, 0xf3, 0x28, 0xb7, 0xcb, 0x48, + 0x85, 0x87, 0x8b, 0xe7, 0x89, 0x52, 0x46, 0x7b, 0xb0, 0x9b, 0xd3, 0x8c, 0x95, 0x9f, 0xe5, 0xce, + 0xe1, 0x57, 0xed, 0x81, 0xc9, 0x87, 0xe3, 0xfe, 0x91, 0xce, 0xac, 0xe3, 0xef, 0x19, 0xeb, 0xeb, + 0xc1, 0xf7, 0x89, 0xce, 0x5c, 0x7a, 0xac, 0x33, 0xcb, 0x62, 0xf6, 0xb1, 0x38, 0xec, 0xfe, 0xb2, + 0x78, 0x0e, 0x7f, 0xf8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x17, 0x8d, 0x29, 0x22, 0x80, 0x0f, + 0x00, 0x00, } diff --git a/common/query/accountBalanceQuery_test.go b/common/query/accountBalanceQuery_test.go index 9d67f7413..30037936d 100644 --- a/common/query/accountBalanceQuery_test.go +++ b/common/query/accountBalanceQuery_test.go @@ -96,7 +96,7 @@ func TestAccountBalanceQuery_AddAccountBalance(t *testing.T) { } func TestAccountBalanceQuery_AddAccountSpendableBalance(t *testing.T) { - t.Run("AddAccountSpendableBalance:succes", func(t *testing.T) { + t.Run("AddAccountSpendableBalance:success", func(t *testing.T) { q, args := mockAccountBalanceQuery.AddAccountSpendableBalance(100, causedFields) wantQ := "UPDATE account_balance SET spendable_balance = spendable_balance + (100) WHERE account_address = ?" wantArg := []interface{}{"BCZ"} diff --git a/common/query/batchReceiptQuery.go b/common/query/batchReceiptQuery.go new file mode 100644 index 000000000..523ee333c --- /dev/null +++ b/common/query/batchReceiptQuery.go @@ -0,0 +1,149 @@ +package query + +import ( + "database/sql" + "fmt" + "strings" + + "github.com/zoobc/zoobc-core/common/constant" + "github.com/zoobc/zoobc-core/common/model" +) + +type ( + // BatchReceiptQueryInterface interface for BatchReceiptQuery + BatchReceiptQueryInterface interface { + InsertBatchReceipt(receipt *model.BatchReceipt) (qStr string, args []interface{}) + GetBatchReceipts(limit uint32, offset uint64) string + RemoveBatchReceiptByRoot(merkleRoot []byte) (qStr string, args []interface{}) + RemoveBatchReceipt(datumType uint32, datumHash []byte) (qStr string, args []interface{}) + ExtractModel(receipt *model.BatchReceipt) []interface{} + BuildModel(receipts []*model.BatchReceipt, rows *sql.Rows) []*model.BatchReceipt + Scan(receipt *model.BatchReceipt, rows *sql.Row) error + } + // BatchReceiptQuery us query for BatchReceipt + BatchReceiptQuery struct { + Fields []string + TableName string + } +) + +// NewBatchReceiptQuery return new BatchReceiptQuery instance +func NewBatchReceiptQuery() *BatchReceiptQuery { + return &BatchReceiptQuery{ + Fields: []string{ + "sender_public_key", + "recipient_public_key", + "datum_type", + "datum_hash", + "reference_block_height", + "reference_block_hash", + "rmr_linked", + "recipient_signature", + }, + TableName: "batch_receipt", + } +} + +func (br *BatchReceiptQuery) getTableName() string { + return br.TableName +} + +// InsertBatchReceipt build insert query for `batch_receipt` table +func (br *BatchReceiptQuery) InsertBatchReceipt(receipt *model.BatchReceipt) (qStr string, args []interface{}) { + return fmt.Sprintf( + "INSERT INTO %s (%s) VALUES(%s)", + br.getTableName(), + strings.Join(br.Fields, ", "), + fmt.Sprintf("? %s", strings.Repeat(", ?", len(br.Fields)-1)), + ), + br.ExtractModel(receipt) +} + +// GetBatchReceipts build select query for `batch_receipt` table +func (br *BatchReceiptQuery) GetBatchReceipts(limit uint32, offset uint64) string { + + query := fmt.Sprintf( + "SELECT %s FROM %s ", + strings.Join(br.Fields, ", "), + br.getTableName(), + ) + + newLimit := limit + if limit == 0 { + newLimit = constant.ReceiptBatchMaximum + } + query += fmt.Sprintf( + "ORDER BY reference_block_height LIMIT %d OFFSET %d", + newLimit, + offset, + ) + return query +} + +// RemoveBatchReceiptByRoot build delete query for `batch_receipt` table by `receipt_merkle_root` +func (br *BatchReceiptQuery) RemoveBatchReceiptByRoot(root []byte) (qStr string, args []interface{}) { + return fmt.Sprintf( + "DELETE FROM %s WHERE rmr_linked = ?", + br.getTableName(), + ), + []interface{}{root} +} + +// RemoveBatchReceipt query builder to remove `batch_receipt WHERE datum_type = ? AND datum_hash = ?` +func (br *BatchReceiptQuery) RemoveBatchReceipt(datumType uint32, datumHash []byte) (qStr string, args []interface{}) { + return fmt.Sprintf( + "DELETE FROM %s WHERE datum_type = ? AND datum_hash = ?", + br.getTableName(), + ), + []interface{}{datumType, datumHash} +} + +// ExtractModel extract the model struct fields to the order of BatchReceiptQuery.Fields +func (*BatchReceiptQuery) ExtractModel(receipt *model.BatchReceipt) []interface{} { + return []interface{}{ + &receipt.SenderPublicKey, + &receipt.RecipientPublicKey, + &receipt.DatumType, + &receipt.DatumHash, + &receipt.ReferenceBlockHeight, + &receipt.ReferenceBlockHash, + &receipt.RMRLinked, + &receipt.RecipientSignature, + } +} + +// BuildModel extract __*sql.Rows__ into []*model.Receipt +func (*BatchReceiptQuery) BuildModel(receipts []*model.BatchReceipt, rows *sql.Rows) []*model.BatchReceipt { + for rows.Next() { + var receipt model.BatchReceipt + _ = rows.Scan( + &receipt.SenderPublicKey, + &receipt.RecipientPublicKey, + &receipt.DatumType, + &receipt.DatumHash, + &receipt.ReferenceBlockHeight, + &receipt.ReferenceBlockHash, + &receipt.RMRLinked, + &receipt.RecipientSignature, + ) + + receipts = append(receipts, &receipt) + } + return receipts +} + +func (*BatchReceiptQuery) Scan(receipt *model.BatchReceipt, row *sql.Row) error { + + err := row.Scan( + &receipt.SenderPublicKey, + &receipt.RecipientPublicKey, + &receipt.DatumType, + &receipt.DatumHash, + &receipt.ReferenceBlockHeight, + &receipt.ReferenceBlockHash, + &receipt.RMRLinked, + &receipt.RecipientSignature, + ) + return err + +} diff --git a/common/query/batchReceiptQuery_test.go b/common/query/batchReceiptQuery_test.go new file mode 100644 index 000000000..a1a8c2cde --- /dev/null +++ b/common/query/batchReceiptQuery_test.go @@ -0,0 +1,396 @@ +package query + +import ( + "database/sql" + "fmt" + "reflect" + "strings" + "testing" + + "github.com/DATA-DOG/go-sqlmock" + "github.com/zoobc/zoobc-core/common/model" +) + +var ( + mockBatchQuery = NewBatchReceiptQuery() + mockBatchReceipt = &model.BatchReceipt{ + SenderPublicKey: []byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"), + RecipientPublicKey: []byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"), + DatumType: uint32(1), + DatumHash: []byte{1, 2, 3, 4, 5, 6}, + ReferenceBlockHeight: uint32(1), + ReferenceBlockHash: []byte{1, 2, 3, 4, 5, 6}, + RMRLinked: []byte{1, 2, 3, 4, 5, 6}, + RecipientSignature: []byte{1, 2, 3, 4, 5, 6}, + } +) + +func TestNewBatchReceiptQuery(t *testing.T) { + tests := []struct { + name string + want *BatchReceiptQuery + }{ + { + name: "wantSuccess", + want: mockBatchQuery, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewBatchReceiptQuery(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewBatchReceiptQuery() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBatchReceiptQuery_getTableName(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "wantSuccess", + fields: fields(*mockBatchQuery), + want: "batch_receipt", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + br := &BatchReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + if got := br.getTableName(); got != tt.want { + t.Errorf("BatchReceiptQuery.getTableName() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBatchReceiptQuery_InsertBatchReceipt(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + receipt *model.BatchReceipt + } + tests := []struct { + name string + fields fields + args args + wantQStr string + wantArgs []interface{} + }{ + { + name: "wantSuccess", + fields: fields(*mockBatchQuery), + args: args{ + receipt: mockBatchReceipt, + }, + wantQStr: fmt.Sprintf( + "INSERT INTO batch_receipt (%s) VALUES(%s)", + strings.Join(mockBatchQuery.Fields, ", "), + fmt.Sprintf("? %s", strings.Repeat(", ?", len(mockBatchQuery.Fields)-1)), + ), + wantArgs: mockBatchQuery.ExtractModel(mockBatchReceipt), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + br := &BatchReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + gotQStr, gotArgs := br.InsertBatchReceipt(tt.args.receipt) + if gotQStr != tt.wantQStr { + t.Errorf("BatchReceiptQuery.InsertBatchReceipt() gotQStr = \n%v, want \n%v", gotQStr, tt.wantQStr) + } + if !reflect.DeepEqual(gotArgs, tt.wantArgs) { + t.Errorf("BatchReceiptQuery.InsertBatchReceipt() gotArgs = %v, want %v", gotArgs, tt.wantArgs) + } + }) + } +} + +func TestBatchReceiptQuery_GetBatchReceipts(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "wantSuccess", + fields: fields(*mockBatchQuery), + want: "SELECT sender_public_key, recipient_public_key, datum_type, datum_hash, " + + "reference_block_height, reference_block_hash, rmr_linked, recipient_signature " + + "FROM batch_receipt ORDER BY reference_block_height LIMIT 10 OFFSET 0", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + br := &BatchReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + if got := br.GetBatchReceipts(10, 0); got != tt.want { + t.Errorf("BatchReceiptQuery.GetBatchReceipts() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBatchReceiptQuery_ExtractModel(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + receipt *model.BatchReceipt + } + tests := []struct { + name string + fields fields + args args + want []interface{} + }{ + { + name: "wantSuccess", + fields: fields(*mockBatchQuery), + args: args{ + receipt: mockBatchReceipt, + }, + want: mockBatchQuery.ExtractModel(mockBatchReceipt), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + b := &BatchReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + if got := b.ExtractModel(tt.args.receipt); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BatchReceiptQuery.ExtractModel() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBatchReceiptQuery_RemoveBatchReceiptByRoot(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + root []byte + } + tests := []struct { + name string + fields fields + args args + wantQStr string + wantArgs []interface{} + }{ + { + name: "wantSuccess", + fields: fields(*mockBatchQuery), + args: args{ + root: []byte{1, 2, 3}, + }, + wantQStr: "DELETE FROM batch_receipt WHERE rmr_linked = ?", + wantArgs: []interface{}{[]byte{1, 2, 3}}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + br := &BatchReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + gotQStr, gotArgs := br.RemoveBatchReceiptByRoot(tt.args.root) + if gotQStr != tt.wantQStr { + t.Errorf("BatchReceiptQuery.RemoveBatchReceiptByRoot() gotQStr = %v, want %v", gotQStr, tt.wantQStr) + } + if !reflect.DeepEqual(gotArgs, tt.wantArgs) { + t.Errorf("BatchReceiptQuery.RemoveBatchReceiptByRoot() gotArgs = %v, want %v", gotArgs, tt.wantArgs) + } + }) + } +} + +type ( + mockQueryExecutorBatchReceiptBuildModel struct { + Executor + } +) + +func (*mockQueryExecutorBatchReceiptBuildModel) ExecuteSelect(query string, tx bool, args ...interface{}) (*sql.Rows, error) { + db, mock, _ := sqlmock.New() + mock.ExpectQuery("").WillReturnRows(sqlmock.NewRows(mockBatchQuery.Fields).AddRow( + []byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"), + []byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"), + uint32(1), + []byte{1, 2, 3, 4, 5, 6}, + uint32(1), + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + )) + return db.Query("") +} +func TestBatchReceiptQuery_BuildModel(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + receipts []*model.BatchReceipt + rows *sql.Rows + } + rows, _ := (&mockQueryExecutorBatchReceiptBuildModel{}).ExecuteSelect("", false, "") + defer rows.Close() + + tests := []struct { + name string + fields fields + args args + want []*model.BatchReceipt + }{ + { + name: "wantSuccess", + fields: fields(*mockBatchQuery), + args: args{ + receipts: []*model.BatchReceipt{}, + rows: rows, + }, + want: []*model.BatchReceipt{mockBatchReceipt}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + b := &BatchReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + if got := b.BuildModel(tt.args.receipts, tt.args.rows); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BatchReceiptQuery.BuildModel() = \n%v, want \n%v", got, tt.want) + } + }) + } +} + +type ( + mockQueryExecutorBatchReceiptScan struct { + Executor + } +) + +func (*mockQueryExecutorBatchReceiptScan) ExecuteSelectRow(qStr string, args ...interface{}) *sql.Row { + db, mock, _ := sqlmock.New() + mock.ExpectQuery("").WillReturnRows(sqlmock.NewRows(mockBatchQuery.Fields).AddRow( + []byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"), + []byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"), + uint32(1), + []byte{1, 2, 3, 4, 5, 6}, + uint32(1), + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + )) + return db.QueryRow("") +} + +func TestBatchReceiptQuery_Scan(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + receipt *model.BatchReceipt + row *sql.Row + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + { + name: "wantSuccess", + fields: fields(*mockBatchQuery), + args: args{ + receipt: mockBatchReceipt, + row: (&mockQueryExecutorBatchReceiptScan{}).ExecuteSelectRow("", ""), + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + b := &BatchReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + if err := b.Scan(tt.args.receipt, tt.args.row); (err != nil) != tt.wantErr { + t.Errorf("BatchReceiptQuery.Scan() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestBatchReceiptQuery_RemoveBatchReceipt(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + datumType uint32 + datumHash []byte + } + tests := []struct { + name string + fields fields + args args + wantQStr string + wantArgs []interface{} + }{ + { + name: "wantSuccess", + fields: fields(*mockBatchQuery), + args: args{ + datumType: 0, + datumHash: []byte{1, 2, 3, 4, 5, 6}, + }, + wantQStr: "DELETE FROM batch_receipt WHERE datum_type = ? AND datum_hash = ?", + wantArgs: []interface{}{ + uint32(0), + []byte{1, 2, 3, 4, 5, 6}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + br := &BatchReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + gotQStr, gotArgs := br.RemoveBatchReceipt(tt.args.datumType, tt.args.datumHash) + if gotQStr != tt.wantQStr { + t.Errorf("RemoveBatchReceipt() gotQStr = %v, want %v", gotQStr, tt.wantQStr) + } + if !reflect.DeepEqual(gotArgs, tt.wantArgs) { + t.Errorf("RemoveBatchReceipt() gotArgs = %v, want %v", gotArgs, tt.wantArgs) + } + }) + } +} diff --git a/common/query/executor.go b/common/query/executor.go index da6177503..18cd5cbb1 100644 --- a/common/query/executor.go +++ b/common/query/executor.go @@ -9,7 +9,6 @@ import ( ) type ( - // ExecutorInterface interface ExecutorInterface interface { BeginTx() error @@ -111,7 +110,7 @@ func (qe *Executor) ExecuteSelect(query string, tx bool, args ...interface{}) (* } else { return nil, blocker.NewBlocker( blocker.DBErr, - "transacation need to be begun before read the transaction state", + "transaction need to be begun before read the transaction state", ) } } else { diff --git a/common/query/merkleTreeQuery.go b/common/query/merkleTreeQuery.go new file mode 100644 index 000000000..0d53507b0 --- /dev/null +++ b/common/query/merkleTreeQuery.go @@ -0,0 +1,49 @@ +package query + +import ( + "fmt" + "strings" +) + +type ( + // MerkleTreeQueryInterface contain builder func for MerkleTree + MerkleTreeQueryInterface interface { + InsertMerkleTree(root, tree []byte) (qStr string, args []interface{}) + } + // MerkleTreeQuery fields and table name + MerkleTreeQuery struct { + Fields []string + TableName string + } +) + +// NewMerkleTreeQuery func to create new MerkleTreeInterface +func NewMerkleTreeQuery() MerkleTreeQueryInterface { + + return &MerkleTreeQuery{ + Fields: []string{ + "id", + "tree", + }, + TableName: "merkle_tree", + } + +} + +func (mrQ *MerkleTreeQuery) getTableName() string { + + return mrQ.TableName + +} + +// InsertMerkleTree func build insert Query for MerkleTree +func (mrQ *MerkleTreeQuery) InsertMerkleTree(root, tree []byte) (qStr string, args []interface{}) { + + return fmt.Sprintf( + "INSERT INTO %s (%s) VALUES(%s)", + mrQ.getTableName(), + strings.Join(mrQ.Fields, ", "), + fmt.Sprintf("?%s", strings.Repeat(",? ", len(mrQ.Fields)-1)), + ), + []interface{}{root, tree} +} diff --git a/common/query/receiptQuery.go b/common/query/receiptQuery.go index 75c9bd815..4beab0aff 100644 --- a/common/query/receiptQuery.go +++ b/common/query/receiptQuery.go @@ -11,9 +11,11 @@ import ( type ( ReceiptQueryInterface interface { InsertReceipt(receipt *model.Receipt) (str string, args []interface{}) + InsertReceipts(receipts []*model.Receipt) (str string, args []interface{}) GetReceipts(limit uint32, offset uint64) string ExtractModel(receipt *model.Receipt) []interface{} BuildModel(receipts []*model.Receipt, rows *sql.Rows) []*model.Receipt + Scan(receipt *model.Receipt, row *sql.Row) error } ReceiptQuery struct { @@ -32,8 +34,10 @@ func NewReceiptQuery() *ReceiptQuery { "datum_hash", "reference_block_height", "reference_block_hash", - "receipt_merkle_root", + "rmr_linked", "recipient_signature", + "rmr", + "rmr_index", }, TableName: "node_receipt", } @@ -58,40 +62,96 @@ func (rq *ReceiptQuery) GetReceipts(limit uint32, offset uint64) string { // InsertReceipts inserts a new receipts into DB func (rq *ReceiptQuery) InsertReceipt(receipt *model.Receipt) (str string, args []interface{}) { - var value = fmt.Sprintf("? %s", strings.Repeat(", ?", len(rq.Fields)-1)) - query := fmt.Sprintf("INSERT INTO %s (%s) VALUES(%s)", - rq.getTableName(), strings.Join(rq.Fields, ", "), value) - return query, rq.ExtractModel(receipt) + + return fmt.Sprintf( + "INSERT INTO %s (%s) VALUES(%s)", + rq.getTableName(), + strings.Join(rq.Fields, ", "), + fmt.Sprintf("? %s", strings.Repeat(", ? ", len(rq.Fields)-1)), + ), rq.ExtractModel(receipt) +} + +// InsertReceipts build query for bulk store receipts +func (rq *ReceiptQuery) InsertReceipts(receipts []*model.Receipt) (qStr string, args []interface{}) { + + var ( + query string + values []interface{} + ) + + query = fmt.Sprintf( + "INSERT INTO %s (%s) ", + rq.getTableName(), + strings.Join(rq.Fields, ", "), + ) + + for k, receipt := range receipts { + query += fmt.Sprintf("VALUES(?%s)", strings.Repeat(",? ", len(rq.Fields)-1)) + if k < len(receipts)-1 { + query += ", " + } + values = append(values, rq.ExtractModel(receipt)...) + } + return query, values } // ExtractModel extract the model struct fields to the order of ReceiptQuery.Fields func (*ReceiptQuery) ExtractModel(receipt *model.Receipt) []interface{} { return []interface{}{ - &receipt.SenderPublicKey, - &receipt.RecipientPublicKey, - &receipt.DatumType, - &receipt.DatumHash, - &receipt.ReferenceBlockHeight, - &receipt.ReferenceBlockHash, - &receipt.ReceiptMerkleRoot, - &receipt.RecipientSignature, + &receipt.BatchReceipt.SenderPublicKey, + &receipt.BatchReceipt.RecipientPublicKey, + &receipt.BatchReceipt.DatumType, + &receipt.BatchReceipt.DatumHash, + &receipt.BatchReceipt.ReferenceBlockHeight, + &receipt.BatchReceipt.ReferenceBlockHash, + &receipt.BatchReceipt.RMRLinked, + &receipt.BatchReceipt.RecipientSignature, + &receipt.RMR, + &receipt.RMRIndex, } } func (*ReceiptQuery) BuildModel(receipts []*model.Receipt, rows *sql.Rows) []*model.Receipt { + for rows.Next() { - var receipt model.Receipt + var ( + receipt model.Receipt + batchReceipt model.BatchReceipt + ) + _ = rows.Scan( - &receipt.SenderPublicKey, - &receipt.RecipientPublicKey, - &receipt.DatumType, - &receipt.DatumHash, - &receipt.ReferenceBlockHeight, - &receipt.ReferenceBlockHash, - &receipt.ReceiptMerkleRoot, - &receipt.RecipientSignature, + &batchReceipt.SenderPublicKey, + &batchReceipt.RecipientPublicKey, + &batchReceipt.DatumType, + &batchReceipt.DatumHash, + &batchReceipt.ReferenceBlockHeight, + &batchReceipt.ReferenceBlockHash, + &batchReceipt.RMRLinked, + &batchReceipt.RecipientSignature, + &receipt.RMR, + &receipt.RMRIndex, ) + receipt.BatchReceipt = &batchReceipt receipts = append(receipts, &receipt) } + return receipts } + +func (*ReceiptQuery) Scan(receipt *model.Receipt, row *sql.Row) error { + + err := row.Scan( + &receipt.BatchReceipt.SenderPublicKey, + &receipt.BatchReceipt.RecipientPublicKey, + &receipt.BatchReceipt.DatumType, + &receipt.BatchReceipt.DatumHash, + &receipt.BatchReceipt.ReferenceBlockHeight, + &receipt.BatchReceipt.ReferenceBlockHash, + &receipt.BatchReceipt.RMRLinked, + &receipt.BatchReceipt.RecipientSignature, + &receipt.RMR, + &receipt.RMRIndex, + ) + return err + +} diff --git a/common/query/receiptQuery_test.go b/common/query/receiptQuery_test.go new file mode 100644 index 000000000..bbbde61bb --- /dev/null +++ b/common/query/receiptQuery_test.go @@ -0,0 +1,312 @@ +package query + +import ( + "database/sql" + "reflect" + "testing" + + "github.com/DATA-DOG/go-sqlmock" + "github.com/zoobc/zoobc-core/common/model" +) + +var ( + mockReceiptQuery = NewReceiptQuery() + mockReceipt = &model.Receipt{ + BatchReceipt: &model.BatchReceipt{ + SenderPublicKey: []byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"), + RecipientPublicKey: []byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"), + DatumType: uint32(1), + DatumHash: []byte{1, 2, 3, 4, 5, 6}, + ReferenceBlockHeight: uint32(1), + ReferenceBlockHash: []byte{1, 2, 3, 4, 5, 6}, + RMRLinked: []byte{1, 2, 3, 4, 5, 6}, + RecipientSignature: []byte{1, 2, 3, 4, 5, 6}, + }, + RMR: []byte{1, 2, 3, 4, 5, 6}, + RMRIndex: uint32(4), + } +) + +func TestReceiptQuery_InsertReceipts(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + receipts []*model.Receipt + } + tests := []struct { + name string + fields fields + args args + wantQStr string + wantArgs []interface{} + }{ + { + name: "wantSuccess", + fields: fields(*mockReceiptQuery), + args: args{ + receipts: []*model.Receipt{mockReceipt}, + }, + wantQStr: "INSERT INTO node_receipt " + + "(sender_public_key, recipient_public_key, " + + "datum_type, datum_hash, reference_block_height, " + + "reference_block_hash, rmr_linked, recipient_signature, rmr, rmr_index) " + + "VALUES(?,? ,? ,? ,? ,? ,? ,? ,? ,? )", + wantArgs: []interface{}{ + &mockReceipt.BatchReceipt.SenderPublicKey, + &mockReceipt.BatchReceipt.RecipientPublicKey, + &mockReceipt.BatchReceipt.DatumType, + &mockReceipt.BatchReceipt.DatumHash, + &mockReceipt.BatchReceipt.ReferenceBlockHeight, + &mockReceipt.BatchReceipt.ReferenceBlockHash, + &mockReceipt.BatchReceipt.RMRLinked, + &mockReceipt.BatchReceipt.RecipientSignature, + &mockReceipt.RMR, + &mockReceipt.RMRIndex, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rq := &ReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + gotQStr, gotArgs := rq.InsertReceipts(tt.args.receipts) + if gotQStr != tt.wantQStr { + t.Errorf("ReceiptQuery.InsertReceipts() gotQStr = \n%v, want \n%v", gotQStr, tt.wantQStr) + return + } + if !reflect.DeepEqual(gotArgs, tt.wantArgs) { + t.Errorf("ReceiptQuery.InsertReceipts() gotArgs = \n%v, want \n%v", gotArgs, tt.wantArgs) + } + }) + } +} + +func TestReceiptQuery_InsertReceipt(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + receipt *model.Receipt + } + tests := []struct { + name string + fields fields + args args + wantStr string + wantArgs []interface{} + }{ + { + name: "wantSuccess", + fields: fields(*mockReceiptQuery), + args: args{ + receipt: mockReceipt, + }, + wantStr: "INSERT INTO node_receipt " + + "(sender_public_key, recipient_public_key, datum_type, datum_hash, " + + "reference_block_height, reference_block_hash, rmr_linked, " + + "recipient_signature, rmr, rmr_index) VALUES(? , ? , ? , ? , ? , ? , ? , ? , ? , ? )", + wantArgs: []interface{}{ + &mockReceipt.BatchReceipt.SenderPublicKey, + &mockReceipt.BatchReceipt.RecipientPublicKey, + &mockReceipt.BatchReceipt.DatumType, + &mockReceipt.BatchReceipt.DatumHash, + &mockReceipt.BatchReceipt.ReferenceBlockHeight, + &mockReceipt.BatchReceipt.ReferenceBlockHash, + &mockReceipt.BatchReceipt.RMRLinked, + &mockReceipt.BatchReceipt.RecipientSignature, + &mockReceipt.RMR, + &mockReceipt.RMRIndex, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rq := &ReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + gotStr, gotArgs := rq.InsertReceipt(tt.args.receipt) + if gotStr != tt.wantStr { + t.Errorf("ReceiptQuery.InsertReceipt() gotStr = \n%v, want \n%v", gotStr, tt.wantStr) + return + } + if !reflect.DeepEqual(gotArgs, tt.wantArgs) { + t.Errorf("ReceiptQuery.InsertReceipt() gotArgs = \n%v, want \n%v", gotArgs, tt.wantArgs) + } + }) + } +} + +func TestReceiptQuery_GetReceipts(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + limit uint32 + offset uint64 + } + tests := []struct { + name string + fields fields + args args + want string + }{ + { + name: "wantSuccess", + fields: fields(*mockReceiptQuery), + args: args{ + limit: uint32(10), + offset: uint64(0), + }, + want: "SELECT sender_public_key, recipient_public_key, datum_type, " + + "datum_hash, reference_block_height, reference_block_hash, rmr_linked, " + + "recipient_signature, rmr, rmr_index from node_receipt LIMIT 0,10", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rq := &ReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + if got := rq.GetReceipts(tt.args.limit, tt.args.offset); got != tt.want { + t.Errorf("ReceiptQuery.GetReceipts() = \n%v, want \n%v", got, tt.want) + } + }) + } +} + +type ( + mockQueryExecutorNodeReceiptScan struct { + Executor + } +) + +func (*mockQueryExecutorNodeReceiptScan) ExecuteSelectRow(qStr string, args ...interface{}) *sql.Row { + db, mock, _ := sqlmock.New() + mock.ExpectQuery("").WillReturnRows(sqlmock.NewRows(mockReceiptQuery.Fields).AddRow( + []byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"), + []byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"), + uint32(1), + []byte{1, 2, 3, 4, 5, 6}, + uint32(1), + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + uint32(4), + )) + return db.QueryRow("") +} + +func TestReceiptQuery_Scan(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + receipt *model.Receipt + row *sql.Row + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + { + name: "wantSuccess", + fields: fields(*mockReceiptQuery), + args: args{ + receipt: mockReceipt, + row: (&mockQueryExecutorNodeReceiptScan{}).ExecuteSelectRow("", ""), + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + r := &ReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + if err := r.Scan(tt.args.receipt, tt.args.row); (err != nil) != tt.wantErr { + t.Errorf("ReceiptQuery.Scan() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +type ( + mockQueryExecutorNodeReceiptBuildModel struct { + Executor + } +) + +func (*mockQueryExecutorNodeReceiptBuildModel) ExecuteSelect(query string, tx bool, args ...interface{}) (*sql.Rows, error) { + db, mock, _ := sqlmock.New() + mock.ExpectQuery("").WillReturnRows(sqlmock.NewRows(mockReceiptQuery.Fields).AddRow( + []byte("BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"), + []byte("BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J"), + uint32(1), + []byte{1, 2, 3, 4, 5, 6}, + uint32(1), + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + []byte{1, 2, 3, 4, 5, 6}, + uint32(4), + )) + return db.Query("") +} + +func TestReceiptQuery_BuildModel(t *testing.T) { + type fields struct { + Fields []string + TableName string + } + type args struct { + receipts []*model.Receipt + rows *sql.Rows + } + rows, err := (&mockQueryExecutorNodeReceiptBuildModel{}).ExecuteSelect("", false, "") + if err != nil { + t.Errorf("Rows Failed: %s", err.Error()) + return + } + defer rows.Close() + + tests := []struct { + name string + fields fields + args args + want []*model.Receipt + }{ + { + name: "wantSuccess", + fields: fields(*mockReceiptQuery), + args: args{ + receipts: []*model.Receipt{}, + rows: rows, + }, + want: []*model.Receipt{mockReceipt}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + re := &ReceiptQuery{ + Fields: tt.fields.Fields, + TableName: tt.fields.TableName, + } + if got := re.BuildModel(tt.args.receipts, tt.args.rows); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BuildModel() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/common/query/transactionQuery_test.go b/common/query/transactionQuery_test.go index 9847f1b3d..8b579c0b6 100644 --- a/common/query/transactionQuery_test.go +++ b/common/query/transactionQuery_test.go @@ -298,12 +298,12 @@ func TestTransactionQuery_GetTransactionsByBlockID(t *testing.T) { } type ( - mockQueryExecutorBuildMmodel struct { + mockQueryExecutorBuildModel struct { Executor } ) -func (*mockQueryExecutorBuildMmodel) ExecuteSelect(query string, tx bool, args ...interface{}) (*sql.Rows, error) { +func (*mockQueryExecutorBuildModel) ExecuteSelect(query string, tx bool, args ...interface{}) (*sql.Rows, error) { db, mock, _ := sqlmock.New() mock.ExpectQuery("").WillReturnRows( sqlmock.NewRows(mockTransactionQuery.Fields).AddRow( @@ -335,7 +335,7 @@ func TestTransactionQuery_BuildModel(t *testing.T) { txs []*model.Transaction rows *sql.Rows } - rows, _ := (&mockQueryExecutorBuildMmodel{}).ExecuteSelect("", false) + rows, _ := (&mockQueryExecutorBuildModel{}).ExecuteSelect("", false) tests := []struct { name string fields fields diff --git a/common/schema b/common/schema index 5c72aa3a3..ba7a48fd3 160000 --- a/common/schema +++ b/common/schema @@ -1 +1 @@ -Subproject commit 5c72aa3a3cd11c34ec19284074146c5d42dc5268 +Subproject commit ba7a48fd3644ee184a5debf6b16d5b334548cb1e diff --git a/common/service/block.pb.go b/common/service/block.pb.go index 8dcdc9f76..a32218286 100644 --- a/common/service/block.pb.go +++ b/common/service/block.pb.go @@ -10,8 +10,6 @@ import ( model "github.com/zoobc/zoobc-core/common/model" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -95,17 +93,6 @@ type BlockServiceServer interface { GetBlock(context.Context, *model.GetBlockRequest) (*model.BlockExtendedInfo, error) } -// UnimplementedBlockServiceServer can be embedded to have forward compatible implementations. -type UnimplementedBlockServiceServer struct { -} - -func (*UnimplementedBlockServiceServer) GetBlocks(ctx context.Context, req *model.GetBlocksRequest) (*model.GetBlocksResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBlocks not implemented") -} -func (*UnimplementedBlockServiceServer) GetBlock(ctx context.Context, req *model.GetBlockRequest) (*model.BlockExtendedInfo, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetBlock not implemented") -} - func RegisterBlockServiceServer(s *grpc.Server, srv BlockServiceServer) { s.RegisterService(&_BlockService_serviceDesc, srv) } diff --git a/common/service/block.pb.gw.go b/common/service/block.pb.gw.go index be9a0db90..6f1dba3b6 100644 --- a/common/service/block.pb.gw.go +++ b/common/service/block.pb.gw.go @@ -37,10 +37,7 @@ func request_BlockService_GetBlocks_0(ctx context.Context, marshaler runtime.Mar var protoReq model.GetBlocksRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_BlockService_GetBlocks_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_BlockService_GetBlocks_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -57,10 +54,7 @@ func request_BlockService_GetBlock_0(ctx context.Context, marshaler runtime.Mars var protoReq model.GetBlockRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_BlockService_GetBlock_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_BlockService_GetBlock_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -151,9 +145,9 @@ func RegisterBlockServiceHandlerClient(ctx context.Context, mux *runtime.ServeMu } var ( - pattern_BlockService_GetBlocks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "block", "GetBlocks"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_BlockService_GetBlocks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "block", "GetBlocks"}, "")) - pattern_BlockService_GetBlock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "block", "GetBlock"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_BlockService_GetBlock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "block", "GetBlock"}, "")) ) var ( diff --git a/common/service/p2pCommunication.pb.go b/common/service/p2pCommunication.pb.go index 4504b0b29..dea3ab73b 100644 --- a/common/service/p2pCommunication.pb.go +++ b/common/service/p2pCommunication.pb.go @@ -9,8 +9,6 @@ import ( proto "github.com/golang/protobuf/proto" model "github.com/zoobc/zoobc-core/common/model" grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -28,33 +26,34 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package func init() { proto.RegisterFile("service/p2pCommunication.proto", fileDescriptor_5d547fbc25d9babc) } var fileDescriptor_5d547fbc25d9babc = []byte{ - // 414 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x6b, 0xd4, 0x40, - 0x14, 0xc7, 0x73, 0x51, 0x71, 0x5a, 0x6d, 0x3b, 0x82, 0x8b, 0x29, 0xf5, 0x10, 0x50, 0x54, 0x34, - 0x81, 0x55, 0xf4, 0xe0, 0xc9, 0xed, 0x4a, 0x28, 0xd2, 0xb2, 0xac, 0x9e, 0xbc, 0x25, 0x93, 0xb7, - 0x76, 0x34, 0x33, 0x2f, 0xce, 0xbc, 0x14, 0xeb, 0xbf, 0xe4, 0x3f, 0x29, 0xc9, 0x4c, 0x7e, 0x41, - 0xc4, 0x5e, 0xf6, 0xf0, 0xf9, 0xfe, 0x78, 0xf3, 0xde, 0xee, 0xb2, 0xc7, 0x16, 0xcc, 0x95, 0x14, - 0x90, 0x54, 0xcb, 0xea, 0x14, 0x95, 0xaa, 0xb5, 0x14, 0x19, 0x49, 0xd4, 0x71, 0x65, 0x90, 0x90, - 0xdf, 0xf1, 0x7a, 0x78, 0xa8, 0xb0, 0x80, 0x32, 0xa9, 0x00, 0x8c, 0x93, 0x3a, 0xa2, 0xb1, 0x00, - 0x4f, 0x8e, 0x1c, 0x01, 0x55, 0xd1, 0xf5, 0x14, 0xe5, 0x25, 0x8a, 0x1f, 0x1e, 0x3d, 0x1c, 0x21, - 0x71, 0x99, 0x49, 0x3f, 0x2a, 0x5c, 0x38, 0x4e, 0x26, 0xd3, 0x36, 0x13, 0xc3, 0x1b, 0xc2, 0x07, - 0x4e, 0x30, 0x20, 0x40, 0x56, 0xe4, 0xe0, 0xf2, 0xcf, 0x2d, 0x76, 0xb8, 0x59, 0x6e, 0x26, 0x6f, - 0xe6, 0xef, 0xd8, 0x5e, 0x0a, 0xb4, 0x01, 0x30, 0x67, 0x7a, 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c6, - 0x21, 0xcb, 0x8f, 0x67, 0xaa, 0xfa, 0xa2, 0xa3, 0x71, 0x91, 0x5d, 0x67, 0x94, 0x45, 0xc1, 0xea, - 0xe5, 0xd7, 0x17, 0xdf, 0x24, 0x5d, 0xd6, 0x79, 0x2c, 0x50, 0x25, 0xbf, 0x11, 0x73, 0xe1, 0x3e, - 0x5f, 0x09, 0x34, 0x90, 0x88, 0x76, 0xa1, 0xc4, 0xff, 0xd7, 0xf2, 0xdb, 0xed, 0x4f, 0xfc, 0xf5, - 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2c, 0xe4, 0xbc, 0xd5, 0x9d, 0x03, 0x00, 0x00, + // 418 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x6f, 0x94, 0x40, + 0x14, 0xc7, 0xf7, 0xa2, 0xc6, 0x69, 0x4d, 0xdb, 0x39, 0xb8, 0x95, 0xa6, 0x3d, 0x6c, 0xa2, 0x51, + 0xa3, 0x90, 0xac, 0x26, 0x1e, 0xbc, 0x68, 0xbb, 0x86, 0x34, 0xa6, 0xcd, 0x06, 0x3d, 0x79, 0x1b, + 0x86, 0xb7, 0xee, 0x28, 0x33, 0x0f, 0x99, 0x47, 0xe3, 0xfa, 0xff, 0xf9, 0x7f, 0x19, 0x60, 0x18, + 0x20, 0x62, 0xec, 0x85, 0xc3, 0xe7, 0xfb, 0xe3, 0xcd, 0x3c, 0x80, 0x9d, 0x59, 0x28, 0x6f, 0x94, + 0x84, 0xa8, 0x58, 0x16, 0x17, 0xa8, 0x75, 0x65, 0x94, 0x14, 0xa4, 0xd0, 0x84, 0x45, 0x89, 0x84, + 0xfc, 0x9e, 0xd3, 0x83, 0x43, 0x8d, 0x19, 0xe4, 0x51, 0x01, 0x50, 0xb6, 0x52, 0x47, 0x0c, 0x66, + 0xe0, 0xc8, 0x51, 0x4b, 0x40, 0x17, 0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x67, 0xf3, 0xb3, 0x2c, + 0x0b, 0x6a, 0x13, 0x6a, 0x8d, 0xe6, 0x4a, 0xe5, 0x60, 0x09, 0x0d, 0x34, 0x97, 0xbc, 0x5c, 0x59, + 0xfe, 0x74, 0xd0, 0x33, 0x65, 0xc9, 0xfc, 0x66, 0x9f, 0xdd, 0xc2, 0xe9, 0x87, 0x7e, 0x64, 0x07, + 0x31, 0xd0, 0x35, 0xfc, 0x24, 0x3f, 0xe9, 0xb4, 0xcf, 0xf7, 0xbc, 0xaf, 0xef, 0xde, 0xcd, 0x44, + 0xd9, 0x7b, 0xf6, 0x60, 0x18, 0xb2, 0xfc, 0x64, 0xa2, 0xca, 0x17, 0x1d, 0x0d, 0x8b, 0xec, 0x4a, + 0x90, 0x58, 0xcc, 0xce, 0x5f, 0x7c, 0x79, 0xfe, 0x55, 0xd1, 0xb6, 0x4a, 0x43, 0x89, 0x3a, 0xfa, + 0x85, 0x98, 0xca, 0xf6, 0xf9, 0x52, 0x62, 0x09, 0x91, 0x6c, 0x2e, 0x14, 0xb9, 0x5f, 0x31, 0xbd, + 0xdb, 0x7c, 0xfc, 0xaf, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x35, 0x83, 0x46, 0x21, 0xbc, 0x03, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -72,8 +71,8 @@ type P2PCommunicationClient interface { GetPeerInfo(ctx context.Context, in *model.GetPeerInfoRequest, opts ...grpc.CallOption) (*model.Node, error) GetMorePeers(ctx context.Context, in *model.Empty, opts ...grpc.CallOption) (*model.GetMorePeersResponse, error) SendPeers(ctx context.Context, in *model.SendPeersRequest, opts ...grpc.CallOption) (*model.Empty, error) - SendBlock(ctx context.Context, in *model.SendBlockRequest, opts ...grpc.CallOption) (*model.Receipt, error) - SendTransaction(ctx context.Context, in *model.SendTransactionRequest, opts ...grpc.CallOption) (*model.Receipt, error) + SendBlock(ctx context.Context, in *model.SendBlockRequest, opts ...grpc.CallOption) (*model.SendBlockResponse, error) + SendTransaction(ctx context.Context, in *model.SendTransactionRequest, opts ...grpc.CallOption) (*model.SendTransactionResponse, error) GetCumulativeDifficulty(ctx context.Context, in *model.GetCumulativeDifficultyRequest, opts ...grpc.CallOption) (*model.GetCumulativeDifficultyResponse, error) GetCommonMilestoneBlockIDs(ctx context.Context, in *model.GetCommonMilestoneBlockIdsRequest, opts ...grpc.CallOption) (*model.GetCommonMilestoneBlockIdsResponse, error) GetNextBlockIDs(ctx context.Context, in *model.GetNextBlockIdsRequest, opts ...grpc.CallOption) (*model.BlockIdsResponse, error) @@ -115,8 +114,8 @@ func (c *p2PCommunicationClient) SendPeers(ctx context.Context, in *model.SendPe return out, nil } -func (c *p2PCommunicationClient) SendBlock(ctx context.Context, in *model.SendBlockRequest, opts ...grpc.CallOption) (*model.Receipt, error) { - out := new(model.Receipt) +func (c *p2PCommunicationClient) SendBlock(ctx context.Context, in *model.SendBlockRequest, opts ...grpc.CallOption) (*model.SendBlockResponse, error) { + out := new(model.SendBlockResponse) err := c.cc.Invoke(ctx, "/service.P2PCommunication/SendBlock", in, out, opts...) if err != nil { return nil, err @@ -124,8 +123,8 @@ func (c *p2PCommunicationClient) SendBlock(ctx context.Context, in *model.SendBl return out, nil } -func (c *p2PCommunicationClient) SendTransaction(ctx context.Context, in *model.SendTransactionRequest, opts ...grpc.CallOption) (*model.Receipt, error) { - out := new(model.Receipt) +func (c *p2PCommunicationClient) SendTransaction(ctx context.Context, in *model.SendTransactionRequest, opts ...grpc.CallOption) (*model.SendTransactionResponse, error) { + out := new(model.SendTransactionResponse) err := c.cc.Invoke(ctx, "/service.P2PCommunication/SendTransaction", in, out, opts...) if err != nil { return nil, err @@ -174,46 +173,14 @@ type P2PCommunicationServer interface { GetPeerInfo(context.Context, *model.GetPeerInfoRequest) (*model.Node, error) GetMorePeers(context.Context, *model.Empty) (*model.GetMorePeersResponse, error) SendPeers(context.Context, *model.SendPeersRequest) (*model.Empty, error) - SendBlock(context.Context, *model.SendBlockRequest) (*model.Receipt, error) - SendTransaction(context.Context, *model.SendTransactionRequest) (*model.Receipt, error) + SendBlock(context.Context, *model.SendBlockRequest) (*model.SendBlockResponse, error) + SendTransaction(context.Context, *model.SendTransactionRequest) (*model.SendTransactionResponse, error) GetCumulativeDifficulty(context.Context, *model.GetCumulativeDifficultyRequest) (*model.GetCumulativeDifficultyResponse, error) GetCommonMilestoneBlockIDs(context.Context, *model.GetCommonMilestoneBlockIdsRequest) (*model.GetCommonMilestoneBlockIdsResponse, error) GetNextBlockIDs(context.Context, *model.GetNextBlockIdsRequest) (*model.BlockIdsResponse, error) GetNextBlocks(context.Context, *model.GetNextBlocksRequest) (*model.BlocksData, error) } -// UnimplementedP2PCommunicationServer can be embedded to have forward compatible implementations. -type UnimplementedP2PCommunicationServer struct { -} - -func (*UnimplementedP2PCommunicationServer) GetPeerInfo(ctx context.Context, req *model.GetPeerInfoRequest) (*model.Node, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetPeerInfo not implemented") -} -func (*UnimplementedP2PCommunicationServer) GetMorePeers(ctx context.Context, req *model.Empty) (*model.GetMorePeersResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetMorePeers not implemented") -} -func (*UnimplementedP2PCommunicationServer) SendPeers(ctx context.Context, req *model.SendPeersRequest) (*model.Empty, error) { - return nil, status.Errorf(codes.Unimplemented, "method SendPeers not implemented") -} -func (*UnimplementedP2PCommunicationServer) SendBlock(ctx context.Context, req *model.SendBlockRequest) (*model.Receipt, error) { - return nil, status.Errorf(codes.Unimplemented, "method SendBlock not implemented") -} -func (*UnimplementedP2PCommunicationServer) SendTransaction(ctx context.Context, req *model.SendTransactionRequest) (*model.Receipt, error) { - return nil, status.Errorf(codes.Unimplemented, "method SendTransaction not implemented") -} -func (*UnimplementedP2PCommunicationServer) GetCumulativeDifficulty(ctx context.Context, req *model.GetCumulativeDifficultyRequest) (*model.GetCumulativeDifficultyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetCumulativeDifficulty not implemented") -} -func (*UnimplementedP2PCommunicationServer) GetCommonMilestoneBlockIDs(ctx context.Context, req *model.GetCommonMilestoneBlockIdsRequest) (*model.GetCommonMilestoneBlockIdsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetCommonMilestoneBlockIDs not implemented") -} -func (*UnimplementedP2PCommunicationServer) GetNextBlockIDs(ctx context.Context, req *model.GetNextBlockIdsRequest) (*model.BlockIdsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetNextBlockIDs not implemented") -} -func (*UnimplementedP2PCommunicationServer) GetNextBlocks(ctx context.Context, req *model.GetNextBlocksRequest) (*model.BlocksData, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetNextBlocks not implemented") -} - func RegisterP2PCommunicationServer(s *grpc.Server, srv P2PCommunicationServer) { s.RegisterService(&_P2PCommunication_serviceDesc, srv) } diff --git a/common/util/receipt.go b/common/util/batchReceipt.go similarity index 56% rename from common/util/receipt.go rename to common/util/batchReceipt.go index 9532aa617..2f2de74a9 100644 --- a/common/util/receipt.go +++ b/common/util/batchReceipt.go @@ -2,33 +2,48 @@ package util import ( "bytes" + "github.com/zoobc/zoobc-core/common/model" ) // GenerateReceipt generate receipt object that act as proof of receipt on data. Data received can be // block, transaction, etc. // generated receipt will not be signed yet (RecipientSignature = nil), will need to be signed using SignReceipt method. -// todo: andy-shi88: receipt merkle root value is not assigned yet -func GenerateReceipt( +func GenerateBatchReceipt( referenceBlock *model.Block, senderPublicKey, recipientPublicKey, datumHash []byte, datumType uint32, -) (*model.Receipt, error) { +) (*model.BatchReceipt, error) { refBlockHash, _ := GetBlockHash(referenceBlock) - return &model.Receipt{ + return &model.BatchReceipt{ SenderPublicKey: senderPublicKey, RecipientPublicKey: recipientPublicKey, DatumType: datumType, DatumHash: datumHash, ReferenceBlockHeight: referenceBlock.Height, ReferenceBlockHash: refBlockHash, - ReceiptMerkleRoot: nil, }, nil } -func GetUnsignedReceiptBytes( - receipt *model.Receipt, +// GetUnsignedReceiptBytes Client task while doing validation signature +func GetUnsignedBatchReceiptBytes( + receipt *model.BatchReceipt, ) []byte { + + buffer := bytes.NewBuffer([]byte{}) + buffer.Write(receipt.SenderPublicKey) + buffer.Write(receipt.RecipientPublicKey) + buffer.Write(ConvertUint32ToBytes(receipt.ReferenceBlockHeight)) + buffer.Write(receipt.ReferenceBlockHash) + buffer.Write(ConvertUint32ToBytes(receipt.DatumType)) + buffer.Write(receipt.DatumHash) + buffer.Write(receipt.RMRLinked) + return buffer.Bytes() +} + +// GetSignedReceiptBytes Client task before store into database batch_receipt +func GetSignedBatchReceiptBytes(receipt *model.BatchReceipt) []byte { + buffer := bytes.NewBuffer([]byte{}) buffer.Write(receipt.SenderPublicKey) buffer.Write(receipt.RecipientPublicKey) @@ -36,6 +51,7 @@ func GetUnsignedReceiptBytes( buffer.Write(receipt.ReferenceBlockHash) buffer.Write(ConvertUint32ToBytes(receipt.DatumType)) buffer.Write(receipt.DatumHash) - buffer.Write(receipt.ReceiptMerkleRoot) + buffer.Write(receipt.RMRLinked) + buffer.Write(receipt.RecipientSignature) return buffer.Bytes() } diff --git a/common/util/receipt_test.go b/common/util/batchReceipt_test.go similarity index 89% rename from common/util/receipt_test.go rename to common/util/batchReceipt_test.go index 555b23884..f3ab74fce 100644 --- a/common/util/receipt_test.go +++ b/common/util/batchReceipt_test.go @@ -9,7 +9,7 @@ import ( ) var ( - mockReceipt = &model.Receipt{ + mockReceipt = &model.BatchReceipt{ SenderPublicKey: []byte{1, 2, 3}, RecipientPublicKey: []byte{3, 2, 1}, DatumType: constant.ReceiptDatumTypeBlock, @@ -19,7 +19,7 @@ var ( 167, 255, 198, 248, 191, 30, 215, 102, 81, 193, 71, 86, 160, 97, 214, 98, 245, 128, 255, 77, 228, 59, 73, 250, 130, 216, 10, 75, 128, 248, 67, 74, }, - ReceiptMerkleRoot: nil, + RMRLinked: nil, RecipientSignature: nil, } mockBlock = &model.Block{ @@ -54,7 +54,7 @@ func TestGenerateReceipt(t *testing.T) { tests := []struct { name string args args - want *model.Receipt + want *model.BatchReceipt wantErr bool }{ { @@ -72,7 +72,7 @@ func TestGenerateReceipt(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := GenerateReceipt(tt.args.referenceBlock, tt.args.senderPublicKey, tt.args.recipientPublicKey, + got, err := GenerateBatchReceipt(tt.args.referenceBlock, tt.args.senderPublicKey, tt.args.recipientPublicKey, tt.args.datumHash, tt.args.datumType) if (err != nil) != tt.wantErr { t.Errorf("GenerateReceipt() error = %v, wantErr %v", err, tt.wantErr) @@ -88,7 +88,7 @@ func TestGenerateReceipt(t *testing.T) { func TestGetUnsignedReceiptBytes(t *testing.T) { mockReceipt.DatumHash, _ = GetBlockHash(mockBlock) type args struct { - receipt *model.Receipt + receipt *model.BatchReceipt } tests := []struct { name string @@ -108,7 +108,7 @@ func TestGetUnsignedReceiptBytes(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := GetUnsignedReceiptBytes(tt.args.receipt); !reflect.DeepEqual(got, tt.want) { + if got := GetUnsignedBatchReceiptBytes(tt.args.receipt); !reflect.DeepEqual(got, tt.want) { t.Errorf("GetUnsignedReceiptBytes() = %v, want %v", got, tt.want) } }) diff --git a/common/util/merkleTree.go b/common/util/merkleTree.go index 98691d972..160b53363 100644 --- a/common/util/merkleTree.go +++ b/common/util/merkleTree.go @@ -2,10 +2,11 @@ package util import ( "bytes" - "github.com/zoobc/zoobc-core/common/blocker" - "golang.org/x/crypto/sha3" "math" "reflect" + + "github.com/zoobc/zoobc-core/common/blocker" + "golang.org/x/crypto/sha3" ) type MerkleRoot struct { @@ -35,8 +36,10 @@ func (mr *MerkleRoot) merkle(items []*bytes.Buffer) *bytes.Buffer { if itemLength == 1 { return items[0] } - return mr.hash(mr.merkle(items[:itemLength/2]), mr.merkle(items[itemLength/2:]), - int32(math.Log2(float64(itemLength)))) + return mr.hash( + mr.merkle(items[:itemLength/2]), mr.merkle(items[itemLength/2:]), + int32(math.Log2(float64(itemLength))), + ) } // hash function take the 2 data to be hashed for building merkle tree @@ -94,3 +97,22 @@ func (*MerkleRoot) VerifyLeaf(leaf, root *bytes.Buffer, necessaryHashes []*bytes } return reflect.DeepEqual(lastHash, root.Bytes()) } + +// ToBytes build []byte from HashTree which is a [][]*bytes.Buffer +func (mr *MerkleRoot) ToBytes() (root, tree []byte) { + var ( + r, t *bytes.Buffer + ) + t = bytes.NewBuffer([]byte{}) + r = bytes.NewBuffer([]byte{}) + + for k, buffer := range mr.HashTree { + for _, nestBuf := range buffer { + t.Write(nestBuf.Bytes()) + if k < len(mr.HashTree) { + r.Write(nestBuf.Bytes()) + } + } + } + return r.Bytes(), t.Bytes() +} diff --git a/common/util/transaction.go b/common/util/transaction.go index 214c5abf8..4528a2b97 100644 --- a/common/util/transaction.go +++ b/common/util/transaction.go @@ -3,6 +3,7 @@ package util import ( "bytes" "errors" + "github.com/zoobc/zoobc-core/common/blocker" "github.com/zoobc/zoobc-core/common/constant" diff --git a/core/service/blockCoreService.go b/core/service/blockCoreService.go index ead6352d2..627ea6c63 100644 --- a/core/service/blockCoreService.go +++ b/core/service/blockCoreService.go @@ -14,16 +14,14 @@ import ( "github.com/zoobc/zoobc-core/common/chaintype" "github.com/zoobc/zoobc-core/common/constant" "github.com/zoobc/zoobc-core/common/crypto" + "github.com/zoobc/zoobc-core/common/model" + "github.com/zoobc/zoobc-core/common/query" "github.com/zoobc/zoobc-core/common/transaction" "github.com/zoobc/zoobc-core/common/util" - "github.com/zoobc/zoobc-core/observer" - "golang.org/x/crypto/sha3" - - "github.com/zoobc/zoobc-core/common/query" - - "github.com/zoobc/zoobc-core/common/model" commonUtils "github.com/zoobc/zoobc-core/common/util" coreUtil "github.com/zoobc/zoobc-core/core/util" + "github.com/zoobc/zoobc-core/observer" + "golang.org/x/crypto/sha3" ) type ( @@ -62,7 +60,7 @@ type ( lastBlock, block *model.Block, nodeSecretPhrase string, - ) (*model.Receipt, error) + ) (*model.BatchReceipt, error) GetParticipationScore(nodePublicKey []byte) (int64, error) GetBlockExtendedInfo(block *model.Block) (*model.BlockExtendedInfo, error) } @@ -663,7 +661,7 @@ func (bs *BlockService) ReceiveBlock( senderPublicKey []byte, lastBlock, block *model.Block, nodeSecretPhrase string, -) (*model.Receipt, error) { +) (*model.BatchReceipt, error) { // make sure block has previous block hash if block.GetPreviousBlockHash() != nil { blockUnsignedByte, _ := util.GetBlockByte(block, false) @@ -705,20 +703,21 @@ func (bs *BlockService) ReceiveBlock( // todo: lastblock last applied block, or incoming block? nodePublicKey := util.GetPublicKeyFromSeed(nodeSecretPhrase) blockHash, _ := util.GetBlockHash(block) - receipt, err := util.GenerateReceipt( + batchReceipt, err := util.GenerateBatchReceipt( lastBlock, senderPublicKey, nodePublicKey, blockHash, - constant.ReceiptDatumTypeBlock) + constant.ReceiptDatumTypeBlock, + ) if err != nil { return nil, err } - receipt.RecipientSignature = bs.Signature.SignByNode( - util.GetUnsignedReceiptBytes(receipt), + batchReceipt.RecipientSignature = bs.Signature.SignByNode( + util.GetUnsignedBatchReceiptBytes(batchReceipt), nodeSecretPhrase, ) - return receipt, nil + return batchReceipt, nil } return nil, blocker.NewBlocker( blocker.ValidationErr, diff --git a/core/service/blockCoreService_test.go b/core/service/blockCoreService_test.go index bfc4b5b1c..87e3c9e87 100644 --- a/core/service/blockCoreService_test.go +++ b/core/service/blockCoreService_test.go @@ -1803,7 +1803,7 @@ func TestBlockService_ReceiveBlock(t *testing.T) { name string fields fields args args - want *model.Receipt + want *model.BatchReceipt wantErr bool }{ { @@ -2017,7 +2017,7 @@ func TestBlockService_ReceiveBlock(t *testing.T) { }, }, wantErr: false, - want: &model.Receipt{ + want: &model.BatchReceipt{ SenderPublicKey: []byte{1, 3, 4, 5, 6}, RecipientPublicKey: []byte{ 88, 220, 21, 76, 132, 107, 209, 213, 213, 206, 112, 50, 201, 183, 134, 250, 90, 163, 91, 63, 176, @@ -2031,7 +2031,7 @@ func TestBlockService_ReceiveBlock(t *testing.T) { ReferenceBlockHeight: 0, ReferenceBlockHash: []byte{133, 198, 93, 19, 200, 113, 155, 159, 136, 63, 230, 29, 21, 173, 160, 40, 169, 25, 61, 85, 203, 79, 43, 182, 5, 236, 141, 124, 46, 193, 223, 255}, - ReceiptMerkleRoot: nil, + RMRLinked: nil, RecipientSignature: []byte{}, }, }, @@ -2055,11 +2055,11 @@ func TestBlockService_ReceiveBlock(t *testing.T) { got, err := bs.ReceiveBlock( tt.args.senderPublicKey, tt.args.lastBlock, tt.args.block, tt.args.nodeSecretPhrase) if (err != nil) != tt.wantErr { - t.Errorf("ReceiveBlock() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ReceiveBlock() error = \n%v, wantErr \n%v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ReceiveBlock() got = %v\nwant %v", got, tt.want) + t.Errorf("ReceiveBlock() got = \n%v want \n%v", got, tt.want) } }) } @@ -2223,11 +2223,11 @@ func TestBlockService_GetBlockExtendedInfo(t *testing.T) { } got, err := bs.GetBlockExtendedInfo(tt.args.block) if (err != nil) != tt.wantErr { - t.Errorf("BlockService.GetBlockExtendedInfo() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("BlockService.GetBlockExtendedInfo() error = \n%v, wantErr \n%v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("BlockService.GetBlockExtendedInfo() = %v, want %v", got, tt.want) + t.Errorf("BlockService.GetBlockExtendedInfo() = \n%v, want \n%v", got, tt.want) } }) } diff --git a/core/service/mempoolCoreService.go b/core/service/mempoolCoreService.go index 32387192b..bb06d06b3 100644 --- a/core/service/mempoolCoreService.go +++ b/core/service/mempoolCoreService.go @@ -35,7 +35,7 @@ type ( receivedTxBytes []byte, lastBlock *model.Block, nodeSecretPhrase string, - ) (*model.Receipt, error) + ) (*model.BatchReceipt, error) } // MempoolService contains all transactions in mempool plus a mux to manage locks in concurrency @@ -219,7 +219,7 @@ func (mps *MempoolService) ReceivedTransaction( receivedTxBytes []byte, lastBlock *model.Block, nodeSecretPhrase string, -) (*model.Receipt, error) { +) (*model.BatchReceipt, error) { var ( err error receivedTx *model.Transaction @@ -277,17 +277,18 @@ func (mps *MempoolService) ReceivedTransaction( nodePublicKey := util.GetPublicKeyFromSeed(nodeSecretPhrase) // generate receipt receivedTxHash := sha3.Sum256(receivedTxBytes) - receipt, err := util.GenerateReceipt( // todo: var + receipt, err := util.GenerateBatchReceipt( // todo: var lastBlock, senderPublicKey, nodePublicKey, receivedTxHash[:], - constant.ReceiptDatumTypeTransaction) + constant.ReceiptDatumTypeTransaction, + ) if err != nil { return nil, err } receipt.RecipientSignature = mps.Signature.SignByNode( - util.GetUnsignedReceiptBytes(receipt), + util.GetUnsignedBatchReceiptBytes(receipt), nodeSecretPhrase, ) diff --git a/main.go b/main.go index 6d136abae..3babc6bd5 100644 --- a/main.go +++ b/main.go @@ -137,6 +137,8 @@ func initP2pInstance() { queryExecutor, query.NewReceiptQuery(), nodePublicKey, + query.NewBatchReceiptQuery(), + query.NewMerkleTreeQuery(), ) // init p2p instances diff --git a/p2p/client/peerServiceClient.go b/p2p/client/peerServiceClient.go index 4a1cc2c51..65cc06081 100644 --- a/p2p/client/peerServiceClient.go +++ b/p2p/client/peerServiceClient.go @@ -1,11 +1,13 @@ package client import ( + "bytes" "context" + log "github.com/sirupsen/logrus" "github.com/spf13/viper" - "github.com/zoobc/zoobc-core/common/blocker" "github.com/zoobc/zoobc-core/common/chaintype" + "github.com/zoobc/zoobc-core/common/constant" "github.com/zoobc/zoobc-core/common/interceptor" "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/common/query" @@ -25,13 +27,12 @@ type ( destPeer *model.Peer, block *model.Block, chainType chaintype.ChainType, - ) (*model.Receipt, error) + ) error SendTransaction( destPeer *model.Peer, transactionBytes []byte, chainType chaintype.ChainType, - ) (*model.Receipt, error) - + ) error GetCumulativeDifficulty(*model.Peer, chaintype.ChainType) (*model.GetCumulativeDifficultyResponse, error) GetCommonMilestoneBlockIDs(destPeer *model.Peer, chaintype chaintype.ChainType, lastBlockID, astMilestoneBlockID int64) (*model.GetCommonMilestoneBlockIdsResponse, error) @@ -40,11 +41,13 @@ type ( } // PeerService represent peer service PeerServiceClient struct { - Dialer Dialer - Logger *log.Logger - QueryExecutor query.ExecutorInterface - ReceiptQuery query.ReceiptQueryInterface - NodePublicKey []byte + Dialer Dialer + Logger *log.Logger + QueryExecutor query.ExecutorInterface + ReceiptQuery query.ReceiptQueryInterface + BatchReceiptQuery query.BatchReceiptQueryInterface + MerkleTreeQuery query.MerkleTreeQueryInterface + NodePublicKey []byte } ) @@ -56,6 +59,8 @@ func NewPeerServiceClient( queryExecutor query.ExecutorInterface, receiptQuery query.ReceiptQueryInterface, nodePublicKey []byte, + batchReceiptQuery query.BatchReceiptQueryInterface, + merkleTreeQuery query.MerkleTreeQueryInterface, ) PeerServiceClientInterface { logLevels := viper.GetStringSlice("logLevels") apiLogger, _ := util.InitLogger(".log/", "debugP2PClient.log", logLevels) @@ -72,10 +77,12 @@ func NewPeerServiceClient( } return conn, nil }, - QueryExecutor: queryExecutor, - ReceiptQuery: receiptQuery, - NodePublicKey: nodePublicKey, - Logger: apiLogger, + QueryExecutor: queryExecutor, + ReceiptQuery: receiptQuery, + BatchReceiptQuery: batchReceiptQuery, + MerkleTreeQuery: merkleTreeQuery, + NodePublicKey: nodePublicKey, + Logger: apiLogger, } } @@ -122,33 +129,34 @@ func (psc *PeerServiceClient) SendPeers(destPeer *model.Peer, peersInfo []*model return res, err } -// SendBlock send block to selected peer +// SendBlock send block to selected peer, got Receipt func (psc *PeerServiceClient) SendBlock( destPeer *model.Peer, block *model.Block, chainType chaintype.ChainType, -) (*model.Receipt, error) { +) error { + + var ( + err error + response *model.SendBlockResponse + ) + connection, _ := psc.Dialer(destPeer) defer connection.Close() + p2pClient := service.NewP2PCommunicationClient(connection) - receipt, err := p2pClient.SendBlock(context.Background(), &model.SendBlockRequest{ + response, err = p2pClient.SendBlock(context.Background(), &model.SendBlockRequest{ SenderPublicKey: psc.NodePublicKey, Block: block, ChainType: chainType.GetTypeInt(), }) if err != nil { - return nil, err - } - insertReceiptQ, insertReceiptArg := psc.ReceiptQuery.InsertReceipt(receipt) - _, err = psc.QueryExecutor.ExecuteStatement(insertReceiptQ, insertReceiptArg...) - if err != nil { - return nil, blocker.NewBlocker( - blocker.DBErr, - "fail to save receipt", - ) + return err } - return receipt, err + + err = psc.storeReceipt(response.BatchReceipt) + return err } // SendTransaction send transaction to selected peer @@ -156,33 +164,32 @@ func (psc *PeerServiceClient) SendTransaction( destPeer *model.Peer, transactionBytes []byte, chainType chaintype.ChainType, -) (*model.Receipt, error) { +) error { + var ( + err error + response *model.SendTransactionResponse + ) connection, _ := psc.Dialer(destPeer) defer connection.Close() p2pClient := service.NewP2PCommunicationClient(connection) - receipt, err := p2pClient.SendTransaction(context.Background(), &model.SendTransactionRequest{ + response, err = p2pClient.SendTransaction(context.Background(), &model.SendTransactionRequest{ SenderPublicKey: psc.NodePublicKey, TransactionBytes: transactionBytes, ChainType: chainType.GetTypeInt(), }) if err != nil { - return nil, err - } - insertReceiptQ, insertReceiptArg := psc.ReceiptQuery.InsertReceipt(receipt) - _, err = psc.QueryExecutor.ExecuteStatement(insertReceiptQ, insertReceiptArg...) - if err != nil { - return nil, blocker.NewBlocker( - blocker.DBErr, - "fail to save receipt", - ) + return err } - return receipt, err + err = psc.storeReceipt(response.BatchReceipt) + return err } // GetCumulativeDifficulty request the cumulative difficulty status of a node -func (psc PeerServiceClient) GetCumulativeDifficulty(destPeer *model.Peer, - chaintype chaintype.ChainType) (*model.GetCumulativeDifficultyResponse, error) { +func (psc PeerServiceClient) GetCumulativeDifficulty( + destPeer *model.Peer, + chaintype chaintype.ChainType, +) (*model.GetCumulativeDifficultyResponse, error) { connection, _ := grpc.Dial( p2pUtil.GetFullAddressPeer(destPeer), grpc.WithInsecure(), @@ -201,8 +208,11 @@ func (psc PeerServiceClient) GetCumulativeDifficulty(destPeer *model.Peer, } // GetCommonMilestoneBlockIDs request the blockIds that may act as milestone block -func (psc PeerServiceClient) GetCommonMilestoneBlockIDs(destPeer *model.Peer, chaintype chaintype.ChainType, lastBlockID, - lastMilestoneBlockID int64) (*model.GetCommonMilestoneBlockIdsResponse, error) { +func (psc PeerServiceClient) GetCommonMilestoneBlockIDs( + destPeer *model.Peer, + chaintype chaintype.ChainType, + lastBlockID, lastMilestoneBlockID int64, +) (*model.GetCommonMilestoneBlockIdsResponse, error) { connection, _ := grpc.Dial( p2pUtil.GetFullAddressPeer(destPeer), grpc.WithInsecure(), @@ -223,8 +233,12 @@ func (psc PeerServiceClient) GetCommonMilestoneBlockIDs(destPeer *model.Peer, ch } // GetNextBlockIDs request the blockIds of the next blocks requested -func (psc PeerServiceClient) GetNextBlockIDs(destPeer *model.Peer, chaintype chaintype.ChainType, - blockID int64, limit uint32) (*model.BlockIdsResponse, error) { +func (psc PeerServiceClient) GetNextBlockIDs( + destPeer *model.Peer, + chaintype chaintype.ChainType, + blockID int64, + limit uint32, +) (*model.BlockIdsResponse, error) { connection, _ := grpc.Dial( p2pUtil.GetFullAddressPeer(destPeer), grpc.WithInsecure(), @@ -245,8 +259,12 @@ func (psc PeerServiceClient) GetNextBlockIDs(destPeer *model.Peer, chaintype cha } // GetNextBlocks request the next blocks matching the array of blockIds -func (psc PeerServiceClient) GetNextBlocks(destPeer *model.Peer, chaintype chaintype.ChainType, blockIds []int64, - blockID int64) (*model.BlocksData, error) { +func (psc PeerServiceClient) GetNextBlocks( + destPeer *model.Peer, + chaintype chaintype.ChainType, + blockIds []int64, + blockID int64, +) (*model.BlocksData, error) { connection, _ := grpc.Dial( p2pUtil.GetFullAddressPeer(destPeer), grpc.WithInsecure(), @@ -266,3 +284,97 @@ func (psc PeerServiceClient) GetNextBlocks(destPeer *model.Peer, chaintype chain } return res, err } + +// storeReceipt function will decide to storing receipt into node_receipt or batch_receipt +// and will generate _merkle_root_ +func (psc *PeerServiceClient) storeReceipt(batchReceipt *model.BatchReceipt) error { + + var ( + err error + count uint32 + queries [][]interface{} + batchReceipts []*model.BatchReceipt + receipt *model.Receipt + hashedReceipts []*bytes.Buffer + merkleRoot util.MerkleRoot + ) + + psc.Logger.Info("Insert Batch Receipt") + insertBatchReceiptQ, argsInsertBatchReceiptQ := psc.BatchReceiptQuery.InsertBatchReceipt(batchReceipt) + _, err = psc.QueryExecutor.ExecuteStatement(insertBatchReceiptQ, argsInsertBatchReceiptQ...) + if err != nil { + return err + } + + countBatchReceiptQ := query.GetTotalRecordOfSelect( + psc.BatchReceiptQuery.GetBatchReceipts(constant.ReceiptBatchMaximum, 0), + ) + err = psc.QueryExecutor.ExecuteSelectRow(countBatchReceiptQ).Scan(&count) + if err != nil { + return err + } + psc.Logger.Info("Count Batch Receipts: ", count) + + if count >= constant.ReceiptBatchMaximum { + psc.Logger.Info("Start Store Batch To Receipt: ", count) + getBatchReceiptsQ := psc.BatchReceiptQuery.GetBatchReceipts(constant.ReceiptBatchMaximum, 0) + rows, err := psc.QueryExecutor.ExecuteSelect(getBatchReceiptsQ, false) + if err != nil { + return err + } + defer rows.Close() + + queries = make([][]interface{}, (constant.ReceiptBatchMaximum*2)+1) + batchReceipts = psc.BatchReceiptQuery.BuildModel(batchReceipts, rows) + + for _, b := range batchReceipts { + hashedReceipts = append( + hashedReceipts, + bytes.NewBuffer(util.GetSignedBatchReceiptBytes(b)), + ) + } + _, err = merkleRoot.GenerateMerkleRoot(hashedReceipts) + if err != nil { + return err + } + rootMerkle, treeMerkle := merkleRoot.ToBytes() + + for k, r := range batchReceipts { + + var ( + br = r + rmrIndex = uint32(k) + ) + + receipt = &model.Receipt{ + BatchReceipt: br, + RMR: rootMerkle, + RMRIndex: rmrIndex, + } + insertReceiptQ, insertReceiptArgs := psc.ReceiptQuery.InsertReceipt(receipt) + queries[k] = append([]interface{}{insertReceiptQ}, insertReceiptArgs...) + removeBatchReceiptQ, removeBatchReceiptArgs := psc.BatchReceiptQuery.RemoveBatchReceipt(br.DatumType, br.DatumHash) + queries[(constant.ReceiptBatchMaximum)+uint32(k)] = append([]interface{}{removeBatchReceiptQ}, removeBatchReceiptArgs...) + } + + insertMerkleTreeQ, insertMerkleTreeArgs := psc.MerkleTreeQuery.InsertMerkleTree(rootMerkle, treeMerkle) + queries[len(queries)-1] = append([]interface{}{insertMerkleTreeQ}, insertMerkleTreeArgs...) + + err = psc.QueryExecutor.BeginTx() + if err != nil { + return err + } + err = psc.QueryExecutor.ExecuteTransactions(queries) + if err != nil { + return err + } + err = psc.QueryExecutor.CommitTx() + if err != nil { + return err + } + + return nil + } + + return nil +} diff --git a/p2p/handler/p2pServerHandler.go b/p2p/handler/p2pServerHandler.go index a0234f420..35fbf7f7b 100644 --- a/p2p/handler/p2pServerHandler.go +++ b/p2p/handler/p2pServerHandler.go @@ -51,7 +51,7 @@ func (ss *P2PServerHandler) SendPeers(ctx context.Context, req *model.SendPeersR return ss.Service.SendPeers(req.Peers) } -// GetCumulativeDifficulty responds to the request of the cummulative difficulty status of a node +// GetCumulativeDifficulty responds to the request of the cumulative difficulty status of a node func (ss *P2PServerHandler) GetCumulativeDifficulty(ctx context.Context, req *model.GetCumulativeDifficultyRequest, ) (*model.GetCumulativeDifficultyResponse, error) { @@ -96,15 +96,20 @@ func (ss *P2PServerHandler) GetNextBlocks(ctx context.Context, req *model.GetNex } // SendBlock receive block from other node and calling BlockReceived Event -func (ss *P2PServerHandler) SendBlock(ctx context.Context, req *model.SendBlockRequest) (*model.Receipt, error) { +func (ss *P2PServerHandler) SendBlock(ctx context.Context, req *model.SendBlockRequest) (*model.SendBlockResponse, error) { // todo: validate request return ss.Service.SendBlock( chaintype.GetChainType(req.ChainType), req.Block, req.SenderPublicKey) } // SendTransaction receive transaction from other node and calling TransactionReceived Event -func (ss *P2PServerHandler) SendTransaction(ctx context.Context, req *model.SendTransactionRequest) (*model.Receipt, error) { +func (ss *P2PServerHandler) SendTransaction( + ctx context.Context, + req *model.SendTransactionRequest, +) (*model.SendTransactionResponse, error) { return ss.Service.SendTransaction( - chaintype.GetChainType(req.ChainType), req.TransactionBytes, req.SenderPublicKey, + chaintype.GetChainType(req.ChainType), + req.TransactionBytes, + req.SenderPublicKey, ) } diff --git a/p2p/p2p.go b/p2p/p2p.go index 7fb0c07a7..1e9d654b5 100644 --- a/p2p/p2p.go +++ b/p2p/p2p.go @@ -210,7 +210,7 @@ func (s *Peer2PeerService) SendBlockListener() observer.Listener { for _, peer := range peers { p := peer go func() { - _, _ = s.PeerServiceClient.SendBlock(p, b, chainType) + _ = s.PeerServiceClient.SendBlock(p, b, chainType) }() } }, @@ -227,7 +227,8 @@ func (s *Peer2PeerService) SendTransactionListener() observer.Listener { for _, peer := range peers { p := peer go func() { - _, _ = s.PeerServiceClient.SendTransaction(p, t, chainType) + _ = s.PeerServiceClient.SendTransaction(p, t, chainType) + }() } }, diff --git a/p2p/service/p2pServerService.go b/p2p/service/p2pServerService.go index 48df04d4d..e2d9e916c 100644 --- a/p2p/service/p2pServerService.go +++ b/p2p/service/p2pServerService.go @@ -40,12 +40,12 @@ type ( chainType chaintype.ChainType, block *model.Block, senderPublicKey []byte, - ) (*model.Receipt, error) + ) (*model.SendBlockResponse, error) SendTransaction( chainType chaintype.ChainType, transactionBytes, senderPublicKey []byte, - ) (*model.Receipt, error) + ) (*model.SendTransactionResponse, error) } P2PServerService struct { @@ -62,6 +62,7 @@ func NewP2PServerService( mempoolServices map[int32]coreService.MempoolServiceInterface, nodeSecretPhrase string, ) *P2PServerService { + return &P2PServerService{ PeerExplorer: peerExplorer, BlockServices: blockServices, @@ -96,7 +97,7 @@ func (ps *P2PServerService) SendPeers( return &model.Empty{}, nil } -// GetCumulativeDifficulty responds to the request of the cummulative difficulty status of a node +// GetCumulativeDifficulty responds to the request of the cumulative difficulty status of a node func (ps *P2PServerService) GetCumulativeDifficulty( chainType chaintype.ChainType, ) (*model.GetCumulativeDifficultyResponse, error) { @@ -232,6 +233,7 @@ func (ps *P2PServerService) GetNextBlocks( blockID int64, blockIDList []int64, ) (*model.BlocksData, error) { + // TODO: getting data from cache var blocksMessage []*model.Block blockService := ps.BlockServices[chainType.GetTypeInt()] @@ -261,7 +263,8 @@ func (ps *P2PServerService) SendBlock( chainType chaintype.ChainType, block *model.Block, senderPublicKey []byte, -) (*model.Receipt, error) { +) (*model.SendBlockResponse, error) { + lastBlock, err := ps.BlockServices[chainType.GetTypeInt()].GetLastBlock() if err != nil { return nil, blocker.NewBlocker( @@ -269,13 +272,18 @@ func (ps *P2PServerService) SendBlock( "fail to get last block", ) } - receipt, err := ps.BlockServices[chainType.GetTypeInt()].ReceiveBlock( - senderPublicKey, lastBlock, block, ps.NodeSecretPhrase, + batchReceipt, err := ps.BlockServices[chainType.GetTypeInt()].ReceiveBlock( + senderPublicKey, + lastBlock, + block, + ps.NodeSecretPhrase, ) if err != nil { return nil, err } - return receipt, nil + return &model.SendBlockResponse{ + BatchReceipt: batchReceipt, + }, nil } // SendTransaction receive transaction from other node and calling TransactionReceived Event @@ -283,7 +291,8 @@ func (ps *P2PServerService) SendTransaction( chainType chaintype.ChainType, transactionBytes, senderPublicKey []byte, -) (*model.Receipt, error) { +) (*model.SendTransactionResponse, error) { + lastBlock, err := ps.BlockServices[chainType.GetTypeInt()].GetLastBlock() if err != nil { return nil, blocker.NewBlocker( @@ -291,7 +300,8 @@ func (ps *P2PServerService) SendTransaction( "fail to get last block", ) } - receipt, err := ps.MempoolServices[chainType.GetTypeInt()].ReceivedTransaction( + + batchReceipt, err := ps.MempoolServices[chainType.GetTypeInt()].ReceivedTransaction( senderPublicKey, transactionBytes, lastBlock, @@ -300,5 +310,7 @@ func (ps *P2PServerService) SendTransaction( if err != nil { return nil, err } - return receipt, nil + return &model.SendTransactionResponse{ + BatchReceipt: batchReceipt, + }, nil }