mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
core: change block.ConsensusData to neo3 format
1. Dropped `Base.ConsensusData` block field 2. Added `Block.ConsensusData` field with `Nonce` and `PrimaryIndex` 3. Removed "Neo.Header.GetConsensusData" and "AntShares.Header.GetConsensusData" interops
This commit is contained in:
parent
0de5cb1bde
commit
55fd9f8d24
18 changed files with 196 additions and 109 deletions
|
@ -86,10 +86,10 @@ func (n *neoBlock) Index() uint32 { return n.Block.Index }
|
||||||
func (n *neoBlock) SetIndex(i uint32) { n.Block.Index = i }
|
func (n *neoBlock) SetIndex(i uint32) { n.Block.Index = i }
|
||||||
|
|
||||||
// ConsensusData implements block.Block interface.
|
// ConsensusData implements block.Block interface.
|
||||||
func (n *neoBlock) ConsensusData() uint64 { return n.Block.ConsensusData }
|
func (n *neoBlock) ConsensusData() uint64 { return n.Block.ConsensusData.Nonce }
|
||||||
|
|
||||||
// SetConsensusData implements block.Block interface.
|
// SetConsensusData implements block.Block interface.
|
||||||
func (n *neoBlock) SetConsensusData(nonce uint64) { n.Block.ConsensusData = nonce }
|
func (n *neoBlock) SetConsensusData(nonce uint64) { n.Block.ConsensusData.Nonce = nonce }
|
||||||
|
|
||||||
// NextConsensus implements block.Block interface.
|
// NextConsensus implements block.Block interface.
|
||||||
func (n *neoBlock) NextConsensus() util.Uint160 { return n.Block.NextConsensus }
|
func (n *neoBlock) NextConsensus() util.Uint160 { return n.Block.NextConsensus }
|
||||||
|
|
|
@ -16,6 +16,9 @@ type Block struct {
|
||||||
// The base of the block.
|
// The base of the block.
|
||||||
Base
|
Base
|
||||||
|
|
||||||
|
// Primary index and nonce
|
||||||
|
ConsensusData ConsensusData `json:"consensus_data"`
|
||||||
|
|
||||||
// Transaction list.
|
// Transaction list.
|
||||||
Transactions []*transaction.Transaction `json:"tx"`
|
Transactions []*transaction.Transaction `json:"tx"`
|
||||||
|
|
||||||
|
@ -30,10 +33,12 @@ func (b *Block) Header() *Header {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func merkleTreeFromTransactions(txes []*transaction.Transaction) (*hash.MerkleTree, error) {
|
// computeMerkleTree computes Merkle tree based on actual block's data.
|
||||||
hashes := make([]util.Uint256, len(txes))
|
func (b *Block) computeMerkleTree() (*hash.MerkleTree, error) {
|
||||||
for i, tx := range txes {
|
hashes := make([]util.Uint256, len(b.Transactions)+1)
|
||||||
hashes[i] = tx.Hash()
|
hashes[0] = b.ConsensusData.Hash()
|
||||||
|
for i, tx := range b.Transactions {
|
||||||
|
hashes[i+1] = tx.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash.NewMerkleTree(hashes)
|
return hash.NewMerkleTree(hashes)
|
||||||
|
@ -41,7 +46,7 @@ func merkleTreeFromTransactions(txes []*transaction.Transaction) (*hash.MerkleTr
|
||||||
|
|
||||||
// RebuildMerkleRoot rebuilds the merkleroot of the block.
|
// RebuildMerkleRoot rebuilds the merkleroot of the block.
|
||||||
func (b *Block) RebuildMerkleRoot() error {
|
func (b *Block) RebuildMerkleRoot() error {
|
||||||
merkle, err := merkleTreeFromTransactions(b.Transactions)
|
merkle, err := b.computeMerkleTree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -66,7 +71,7 @@ func (b *Block) Verify() error {
|
||||||
return fmt.Errorf("miner transaction %s is not the first one", tx.Hash().StringLE())
|
return fmt.Errorf("miner transaction %s is not the first one", tx.Hash().StringLE())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
merkle, err := merkleTreeFromTransactions(b.Transactions)
|
merkle, err := b.computeMerkleTree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -92,12 +97,18 @@ func NewBlockFromTrimmedBytes(b []byte) (*Block, error) {
|
||||||
|
|
||||||
block.Script.DecodeBinary(br)
|
block.Script.DecodeBinary(br)
|
||||||
|
|
||||||
lenTX := br.ReadVarUint()
|
lenHashes := br.ReadVarUint()
|
||||||
block.Transactions = make([]*transaction.Transaction, lenTX)
|
if lenHashes > 0 {
|
||||||
for i := 0; i < int(lenTX); i++ {
|
var consensusDataHash util.Uint256
|
||||||
var hash util.Uint256
|
consensusDataHash.DecodeBinary(br)
|
||||||
hash.DecodeBinary(br)
|
lenTX := lenHashes - 1
|
||||||
block.Transactions[i] = transaction.NewTrimmedTX(hash)
|
block.Transactions = make([]*transaction.Transaction, lenTX)
|
||||||
|
for i := 0; i < int(lenTX); i++ {
|
||||||
|
var hash util.Uint256
|
||||||
|
hash.DecodeBinary(br)
|
||||||
|
block.Transactions[i] = transaction.NewTrimmedTX(hash)
|
||||||
|
}
|
||||||
|
block.ConsensusData.DecodeBinary(br)
|
||||||
}
|
}
|
||||||
|
|
||||||
return block, br.Err
|
return block, br.Err
|
||||||
|
@ -112,14 +123,20 @@ func (b *Block) Trim() ([]byte, error) {
|
||||||
buf.WriteB(1)
|
buf.WriteB(1)
|
||||||
b.Script.EncodeBinary(buf.BinWriter)
|
b.Script.EncodeBinary(buf.BinWriter)
|
||||||
|
|
||||||
buf.WriteVarUint(uint64(len(b.Transactions)))
|
buf.WriteVarUint(uint64(len(b.Transactions)) + 1)
|
||||||
|
hash := b.ConsensusData.Hash()
|
||||||
|
hash.EncodeBinary(buf.BinWriter)
|
||||||
|
|
||||||
for _, tx := range b.Transactions {
|
for _, tx := range b.Transactions {
|
||||||
h := tx.Hash()
|
h := tx.Hash()
|
||||||
h.EncodeBinary(buf.BinWriter)
|
h.EncodeBinary(buf.BinWriter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.ConsensusData.EncodeBinary(buf.BinWriter)
|
||||||
if buf.Err != nil {
|
if buf.Err != nil {
|
||||||
return nil, buf.Err
|
return nil, buf.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,14 +144,39 @@ func (b *Block) Trim() ([]byte, error) {
|
||||||
// Serializable interface.
|
// Serializable interface.
|
||||||
func (b *Block) DecodeBinary(br *io.BinReader) {
|
func (b *Block) DecodeBinary(br *io.BinReader) {
|
||||||
b.Base.DecodeBinary(br)
|
b.Base.DecodeBinary(br)
|
||||||
br.ReadArray(&b.Transactions)
|
contentsCount := br.ReadVarUint()
|
||||||
|
if contentsCount == 0 {
|
||||||
|
br.Err = errors.New("invalid block format")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.ConsensusData.DecodeBinary(br)
|
||||||
|
txes := make([]*transaction.Transaction, contentsCount-1)
|
||||||
|
for i := 0; i < int(contentsCount)-1; i++ {
|
||||||
|
tx := new(transaction.Transaction)
|
||||||
|
tx.DecodeBinary(br)
|
||||||
|
txes[i] = tx
|
||||||
|
}
|
||||||
|
b.Transactions = txes
|
||||||
|
merkle, err := b.computeMerkleTree()
|
||||||
|
if err != nil {
|
||||||
|
br.Err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !b.MerkleRoot.Equals(merkle.Root()) {
|
||||||
|
br.Err = errors.New("MerkleRoot mismatch")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeBinary encodes the block to the given BinWriter, implementing
|
// EncodeBinary encodes the block to the given BinWriter, implementing
|
||||||
// Serializable interface.
|
// Serializable interface.
|
||||||
func (b *Block) EncodeBinary(bw *io.BinWriter) {
|
func (b *Block) EncodeBinary(bw *io.BinWriter) {
|
||||||
b.Base.EncodeBinary(bw)
|
b.Base.EncodeBinary(bw)
|
||||||
bw.WriteArray(b.Transactions)
|
bw.WriteVarUint(uint64(len(b.Transactions) + 1))
|
||||||
|
b.ConsensusData.EncodeBinary(bw)
|
||||||
|
for i := 0; i < len(b.Transactions); i++ {
|
||||||
|
b.Transactions[i].EncodeBinary(bw)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare implements the queue Item interface.
|
// Compare implements the queue Item interface.
|
||||||
|
|
|
@ -29,9 +29,6 @@ type Base struct {
|
||||||
// index/height of the block
|
// index/height of the block
|
||||||
Index uint32 `json:"height"`
|
Index uint32 `json:"height"`
|
||||||
|
|
||||||
// Random number also called nonce
|
|
||||||
ConsensusData uint64 `json:"nonce"`
|
|
||||||
|
|
||||||
// Contract address of the next miner
|
// Contract address of the next miner
|
||||||
NextConsensus util.Uint160 `json:"next_consensus"`
|
NextConsensus util.Uint160 `json:"next_consensus"`
|
||||||
|
|
||||||
|
@ -120,7 +117,6 @@ func (b *Base) encodeHashableFields(bw *io.BinWriter) {
|
||||||
bw.WriteBytes(b.MerkleRoot[:])
|
bw.WriteBytes(b.MerkleRoot[:])
|
||||||
bw.WriteU64LE(b.Timestamp)
|
bw.WriteU64LE(b.Timestamp)
|
||||||
bw.WriteU32LE(b.Index)
|
bw.WriteU32LE(b.Index)
|
||||||
bw.WriteU64LE(b.ConsensusData)
|
|
||||||
bw.WriteBytes(b.NextConsensus[:])
|
bw.WriteBytes(b.NextConsensus[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +128,6 @@ func (b *Base) decodeHashableFields(br *io.BinReader) {
|
||||||
br.ReadBytes(b.MerkleRoot[:])
|
br.ReadBytes(b.MerkleRoot[:])
|
||||||
b.Timestamp = br.ReadU64LE()
|
b.Timestamp = br.ReadU64LE()
|
||||||
b.Index = br.ReadU32LE()
|
b.Index = br.ReadU32LE()
|
||||||
b.ConsensusData = br.ReadU64LE()
|
|
||||||
br.ReadBytes(b.NextConsensus[:])
|
br.ReadBytes(b.NextConsensus[:])
|
||||||
|
|
||||||
// Make the hash of the block here so we dont need to do this
|
// Make the hash of the block here so we dont need to do this
|
||||||
|
|
|
@ -73,13 +73,16 @@ func newDumbBlock() *Block {
|
||||||
MerkleRoot: hash.Sha256([]byte("b")),
|
MerkleRoot: hash.Sha256([]byte("b")),
|
||||||
Timestamp: 100500,
|
Timestamp: 100500,
|
||||||
Index: 1,
|
Index: 1,
|
||||||
ConsensusData: 1111,
|
|
||||||
NextConsensus: hash.Hash160([]byte("a")),
|
NextConsensus: hash.Hash160([]byte("a")),
|
||||||
Script: transaction.Witness{
|
Script: transaction.Witness{
|
||||||
VerificationScript: []byte{0x51}, // PUSH1
|
VerificationScript: []byte{0x51}, // PUSH1
|
||||||
InvocationScript: []byte{0x61}, // NOP
|
InvocationScript: []byte{0x61}, // NOP
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
ConsensusData: ConsensusData{
|
||||||
|
PrimaryIndex: 0,
|
||||||
|
Nonce: 1111,
|
||||||
|
},
|
||||||
Transactions: []*transaction.Transaction{
|
Transactions: []*transaction.Transaction{
|
||||||
transaction.NewMinerTX(),
|
transaction.NewMinerTX(),
|
||||||
transaction.NewIssueTX(),
|
transaction.NewIssueTX(),
|
||||||
|
|
52
pkg/core/block/consensus_data.go
Normal file
52
pkg/core/block/consensus_data.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package block
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConsensusData represents primary index and nonce of block in the chain.
|
||||||
|
type ConsensusData struct {
|
||||||
|
// Primary index
|
||||||
|
PrimaryIndex uint32 `json:"primary"`
|
||||||
|
// Random number
|
||||||
|
Nonce uint64 `json:"nonce"`
|
||||||
|
// Hash of the ConsensusData (single SHA256)
|
||||||
|
hash util.Uint256
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecodeBinary implements Serializable interface.
|
||||||
|
func (c *ConsensusData) DecodeBinary(br *io.BinReader) {
|
||||||
|
c.PrimaryIndex = uint32(br.ReadVarUint())
|
||||||
|
c.Nonce = br.ReadU64LE()
|
||||||
|
}
|
||||||
|
|
||||||
|
// EncodeBinary encodes implements Serializable interface.
|
||||||
|
func (c *ConsensusData) EncodeBinary(bw *io.BinWriter) {
|
||||||
|
bw.WriteVarUint(uint64(c.PrimaryIndex))
|
||||||
|
bw.WriteU64LE(c.Nonce)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hash returns the hash of the consensus data.
|
||||||
|
func (c *ConsensusData) Hash() util.Uint256 {
|
||||||
|
if c.hash.Equals(util.Uint256{}) {
|
||||||
|
if c.createHash() != nil {
|
||||||
|
panic("failed to compute hash!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c.hash
|
||||||
|
}
|
||||||
|
|
||||||
|
// createHash creates the hash of the consensus data.
|
||||||
|
func (c *ConsensusData) createHash() error {
|
||||||
|
buf := io.NewBufBinWriter()
|
||||||
|
c.EncodeBinary(buf.BinWriter)
|
||||||
|
if buf.Err != nil {
|
||||||
|
return buf.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
b := buf.Bytes()
|
||||||
|
c.hash = hash.Sha256(b)
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -18,7 +18,6 @@ func TestHeaderEncodeDecode(t *testing.T) {
|
||||||
MerkleRoot: hash.Sha256([]byte("merkleroot")),
|
MerkleRoot: hash.Sha256([]byte("merkleroot")),
|
||||||
Timestamp: uint64(time.Now().UTC().Unix() * 1000),
|
Timestamp: uint64(time.Now().UTC().Unix() * 1000),
|
||||||
Index: 3445,
|
Index: 3445,
|
||||||
ConsensusData: 394949,
|
|
||||||
NextConsensus: util.Uint160{},
|
NextConsensus: util.Uint160{},
|
||||||
Script: transaction.Witness{
|
Script: transaction.Witness{
|
||||||
InvocationScript: []byte{0x10},
|
InvocationScript: []byte{0x10},
|
||||||
|
@ -34,7 +33,6 @@ func TestHeaderEncodeDecode(t *testing.T) {
|
||||||
assert.Equal(t, header.PrevHash, headerDecode.PrevHash, "expected both prev hashes to be equal")
|
assert.Equal(t, header.PrevHash, headerDecode.PrevHash, "expected both prev hashes to be equal")
|
||||||
assert.Equal(t, header.MerkleRoot, headerDecode.MerkleRoot, "expected both merkle roots to be equal")
|
assert.Equal(t, header.MerkleRoot, headerDecode.MerkleRoot, "expected both merkle roots to be equal")
|
||||||
assert.Equal(t, header.Index, headerDecode.Index, "expected both indexes to be equal")
|
assert.Equal(t, header.Index, headerDecode.Index, "expected both indexes to be equal")
|
||||||
assert.Equal(t, header.ConsensusData, headerDecode.ConsensusData, "expected both consensus data fields to be equal")
|
|
||||||
assert.Equal(t, header.NextConsensus, headerDecode.NextConsensus, "expected both next consensus fields to be equal")
|
assert.Equal(t, header.NextConsensus, headerDecode.NextConsensus, "expected both next consensus fields to be equal")
|
||||||
assert.Equal(t, header.Script.InvocationScript, headerDecode.Script.InvocationScript, "expected equal invocation scripts")
|
assert.Equal(t, header.Script.InvocationScript, headerDecode.Script.InvocationScript, "expected equal invocation scripts")
|
||||||
assert.Equal(t, header.Script.VerificationScript, headerDecode.Script.VerificationScript, "expected equal verification scripts")
|
assert.Equal(t, header.Script.VerificationScript, headerDecode.Script.VerificationScript, "expected equal verification scripts")
|
||||||
|
|
|
@ -63,10 +63,13 @@ func newBlock(cfg config.ProtocolConfiguration, index uint32, prev util.Uint256,
|
||||||
PrevHash: prev,
|
PrevHash: prev,
|
||||||
Timestamp: uint64(time.Now().UTC().Unix()) + uint64(index),
|
Timestamp: uint64(time.Now().UTC().Unix()) + uint64(index),
|
||||||
Index: index,
|
Index: index,
|
||||||
ConsensusData: 1111,
|
|
||||||
NextConsensus: witness.ScriptHash(),
|
NextConsensus: witness.ScriptHash(),
|
||||||
Script: witness,
|
Script: witness,
|
||||||
},
|
},
|
||||||
|
ConsensusData: block.ConsensusData{
|
||||||
|
PrimaryIndex: 0,
|
||||||
|
Nonce: 1111,
|
||||||
|
},
|
||||||
Transactions: txs,
|
Transactions: txs,
|
||||||
}
|
}
|
||||||
_ = b.RebuildMerkleRoot()
|
_ = b.RebuildMerkleRoot()
|
||||||
|
@ -132,13 +135,16 @@ func newDumbBlock() *block.Block {
|
||||||
MerkleRoot: hash.Sha256([]byte("b")),
|
MerkleRoot: hash.Sha256([]byte("b")),
|
||||||
Timestamp: 100500,
|
Timestamp: 100500,
|
||||||
Index: 1,
|
Index: 1,
|
||||||
ConsensusData: 1111,
|
|
||||||
NextConsensus: hash.Hash160([]byte("a")),
|
NextConsensus: hash.Hash160([]byte("a")),
|
||||||
Script: transaction.Witness{
|
Script: transaction.Witness{
|
||||||
VerificationScript: []byte{0x51}, // PUSH1
|
VerificationScript: []byte{0x51}, // PUSH1
|
||||||
InvocationScript: []byte{0x61}, // NOP
|
InvocationScript: []byte{0x61}, // NOP
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
ConsensusData: block.ConsensusData{
|
||||||
|
PrimaryIndex: 0,
|
||||||
|
Nonce: 1111,
|
||||||
|
},
|
||||||
Transactions: []*transaction.Transaction{
|
Transactions: []*transaction.Transaction{
|
||||||
{Type: transaction.MinerType},
|
{Type: transaction.MinerType},
|
||||||
{Type: transaction.IssueType},
|
{Type: transaction.IssueType},
|
||||||
|
|
|
@ -48,16 +48,6 @@ func headerGetVersion(ic *interop.Context, v *vm.VM) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// headerGetConsensusData returns consensus data from the header.
|
|
||||||
func headerGetConsensusData(ic *interop.Context, v *vm.VM) error {
|
|
||||||
header, err := popHeaderFromVM(v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v.Estack().PushVal(header.ConsensusData)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// headerGetMerkleRoot returns version from the header.
|
// headerGetMerkleRoot returns version from the header.
|
||||||
func headerGetMerkleRoot(ic *interop.Context, v *vm.VM) error {
|
func headerGetMerkleRoot(ic *interop.Context, v *vm.VM) error {
|
||||||
header, err := popHeaderFromVM(v)
|
header, err := popHeaderFromVM(v)
|
||||||
|
|
|
@ -136,16 +136,6 @@ func TestHeaderGetVersion_Negative(t *testing.T) {
|
||||||
require.Errorf(t, err, "value is not a header or block")
|
require.Errorf(t, err, "value is not a header or block")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHeaderGetConsensusData(t *testing.T) {
|
|
||||||
v, block, context, chain := createVMAndPushBlock(t)
|
|
||||||
defer chain.Close()
|
|
||||||
|
|
||||||
err := headerGetConsensusData(context, v)
|
|
||||||
require.NoError(t, err)
|
|
||||||
value := v.Estack().Pop().Value().(*big.Int)
|
|
||||||
require.Equal(t, block.ConsensusData, value.Uint64())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHeaderGetMerkleRoot(t *testing.T) {
|
func TestHeaderGetMerkleRoot(t *testing.T) {
|
||||||
v, block, context, chain := createVMAndPushBlock(t)
|
v, block, context, chain := createVMAndPushBlock(t)
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
|
|
|
@ -151,7 +151,6 @@ var neoInterops = []interop.Function{
|
||||||
{Name: "Neo.Enumerator.Create", Func: enumerator.Create, Price: 1},
|
{Name: "Neo.Enumerator.Create", Func: enumerator.Create, Price: 1},
|
||||||
{Name: "Neo.Enumerator.Next", Func: enumerator.Next, Price: 1},
|
{Name: "Neo.Enumerator.Next", Func: enumerator.Next, Price: 1},
|
||||||
{Name: "Neo.Enumerator.Value", Func: enumerator.Value, Price: 1},
|
{Name: "Neo.Enumerator.Value", Func: enumerator.Value, Price: 1},
|
||||||
{Name: "Neo.Header.GetConsensusData", Func: headerGetConsensusData, Price: 1},
|
|
||||||
{Name: "Neo.Header.GetHash", Func: headerGetHash, Price: 1},
|
{Name: "Neo.Header.GetHash", Func: headerGetHash, Price: 1},
|
||||||
{Name: "Neo.Header.GetIndex", Func: headerGetIndex, Price: 1},
|
{Name: "Neo.Header.GetIndex", Func: headerGetIndex, Price: 1},
|
||||||
{Name: "Neo.Header.GetMerkleRoot", Func: headerGetMerkleRoot, Price: 1},
|
{Name: "Neo.Header.GetMerkleRoot", Func: headerGetMerkleRoot, Price: 1},
|
||||||
|
@ -229,7 +228,6 @@ var neoInterops = []interop.Function{
|
||||||
{Name: "AntShares.Contract.GetScript", Func: contractGetScript, Price: 1},
|
{Name: "AntShares.Contract.GetScript", Func: contractGetScript, Price: 1},
|
||||||
{Name: "AntShares.Contract.GetStorageContext", Func: contractGetStorageContext, Price: 1},
|
{Name: "AntShares.Contract.GetStorageContext", Func: contractGetStorageContext, Price: 1},
|
||||||
{Name: "AntShares.Contract.Migrate", Func: contractMigrate, Price: 0},
|
{Name: "AntShares.Contract.Migrate", Func: contractMigrate, Price: 0},
|
||||||
{Name: "AntShares.Header.GetConsensusData", Func: headerGetConsensusData, Price: 1},
|
|
||||||
{Name: "AntShares.Header.GetHash", Func: headerGetHash, Price: 1},
|
{Name: "AntShares.Header.GetHash", Func: headerGetHash, Price: 1},
|
||||||
{Name: "AntShares.Header.GetMerkleRoot", Func: headerGetMerkleRoot, Price: 1},
|
{Name: "AntShares.Header.GetMerkleRoot", Func: headerGetMerkleRoot, Price: 1},
|
||||||
{Name: "AntShares.Header.GetNextConsensus", Func: headerGetNextConsensus, Price: 1},
|
{Name: "AntShares.Header.GetNextConsensus", Func: headerGetNextConsensus, Price: 1},
|
||||||
|
|
|
@ -51,7 +51,6 @@ func TestUnexpectedNonInterops(t *testing.T) {
|
||||||
contractGetScript,
|
contractGetScript,
|
||||||
contractGetStorageContext,
|
contractGetStorageContext,
|
||||||
contractIsPayable,
|
contractIsPayable,
|
||||||
headerGetConsensusData,
|
|
||||||
headerGetHash,
|
headerGetHash,
|
||||||
headerGetIndex,
|
headerGetIndex,
|
||||||
headerGetMerkleRoot,
|
headerGetMerkleRoot,
|
||||||
|
|
|
@ -43,7 +43,6 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error)
|
||||||
PrevHash: util.Uint256{},
|
PrevHash: util.Uint256{},
|
||||||
Timestamp: uint64(time.Date(2016, 7, 15, 15, 8, 21, 0, time.UTC).Unix()),
|
Timestamp: uint64(time.Date(2016, 7, 15, 15, 8, 21, 0, time.UTC).Unix()),
|
||||||
Index: 0,
|
Index: 0,
|
||||||
ConsensusData: 2083236893,
|
|
||||||
NextConsensus: nextConsensus,
|
NextConsensus: nextConsensus,
|
||||||
Script: transaction.Witness{
|
Script: transaction.Witness{
|
||||||
InvocationScript: []byte{},
|
InvocationScript: []byte{},
|
||||||
|
@ -90,6 +89,10 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error)
|
||||||
issueTx,
|
issueTx,
|
||||||
deployNativeContracts(),
|
deployNativeContracts(),
|
||||||
},
|
},
|
||||||
|
ConsensusData: block.ConsensusData{
|
||||||
|
PrimaryIndex: 0,
|
||||||
|
Nonce: 2083236893,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = b.RebuildMerkleRoot(); err != nil {
|
if err = b.RebuildMerkleRoot(); err != nil {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestGenesisBlockMainNet(t *testing.T) {
|
||||||
// have been changed. Consequently, hash of the genesis block has been changed.
|
// have been changed. Consequently, hash of the genesis block has been changed.
|
||||||
// Update expected genesis block hash for better times.
|
// Update expected genesis block hash for better times.
|
||||||
// Old hash is "d42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf"
|
// Old hash is "d42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf"
|
||||||
expect := "c8b1429f154c43321283bb634758951186c00bf4529187ed7e2ff2dadfdfc7a8"
|
expect := "4dce83edc5bb9cbdf23d37cfb81dd3c8fc0c331c608d2d893289ae36a62a41eb"
|
||||||
assert.Equal(t, expect, block.Hash().StringLE())
|
assert.Equal(t, expect, block.Hash().StringLE())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,17 +136,17 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetBlockByIndex(5)
|
return c.GetBlockByIndex(5)
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"000000000c9e819ca13abd194ea86727f8dae2c28634a855836755bde0217125611aefe7675b5bd2a90a1f5e74b2e4386162240318f86534f4d3061722ba78b4fe10fe53a9d49e5e00000000050000005704000000000000d60ac443bb800fb08261e75fa5925d747d48586101fd0401407153238e784d759f1093e5911fcbb07f78af3f83a2159d59511b1c31dd4b70311feb9d63531427ac0e30dc3ae6656adda1f31713a7d56ff68a8764af523776cb4048630138d8d402902b66107ef9a50a227e1be8d8ce148f821e58f45430e59b8c034f1b5ed8208f7ce9711942405bb991d4e69232235bafa5476a8f30b92ac7e840947723eafcdfa2e9d75b551b5fc72bdb300cf541d84db5be4f2a5c33d45b0e3ae35a18c33af988c88dd201c823c15fced52eeed66d7defa3fcf7ea1587e8851c40365d8fdf714453d48f030cf3f7744b57d2cd35ad07a7980b58718e3da9e4dfe466f2e1089e8123dfc5d8d6fe679627ae78aa4cb4986cb4805d78becc009544c594534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb010000d5040000d60ac443bb800fb08261e75fa5925d747d4858610500000000000001fd040140947358ca2dd7543c3ff3f6ea1389a72c3d5ee99f47a9d0ef70bd84a9f57384e76271efc682f6741568c55907b1794b9f520f7d35f39382303bf0206945b5009a409f467419a886aebe6b482e6d5787981d98b58b82959a2858045bf5683665a5c25c502481b2d9655c902c5dcc147546bed58175c2ed16f328cc21e999e19741554063cab34f1613932947a1c346416b12b1ca724198016acc5fd760597539eed74f2069cfe2a8383e99595aefa3234d79d64a39e3f4c64e8cea800469a6f790999c408e2438fab244bdb79e67f6dab9cde0063e523bd0c175657a66e84897cd15eec8bf358661666679bf50334664872616faa366825f36873b16dd2add64c418cd5794534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb"}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"0000000062af8cd56d179044215cc8611f75bd96d896f1026c5b42994ae7707df8d82bd3c9f774f449fec7135b506faffaaeee603e2b82e01dec7d0f706789aa1bb983ae0ec7a25e0000000005000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c7763594130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb020057040000000000000000d5040000e903736ceceeceae1806eee0e3ec61e7cce476ce0500000000000001fd08010c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}`,
|
||||||
result: func(c *Client) interface{} { return &block.Block{} },
|
result: func(c *Client) interface{} { return &block.Block{} },
|
||||||
check: func(t *testing.T, c *Client, result interface{}) {
|
check: func(t *testing.T, c *Client, result interface{}) {
|
||||||
res, ok := result.(*block.Block)
|
res, ok := result.(*block.Block)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
assert.Equal(t, uint32(0), res.Version)
|
assert.Equal(t, uint32(0), res.Version)
|
||||||
assert.Equal(t, "d745190c4823eb4d97f7a40a907f931e05380c05070bd71cb09d832d7bca4bb8", res.Hash().StringLE())
|
assert.Equal(t, "424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9", res.Hash().StringLE())
|
||||||
assert.Equal(t, "e7ef1a61257121e0bd55678355a83486c2e2daf82767a84e19bd3aa19c819e0c", res.PrevHash.StringLE())
|
assert.Equal(t, "d32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62", res.PrevHash.StringLE())
|
||||||
assert.Equal(t, "53fe10feb478ba221706d3f43465f8180324626138e4b2745e1f0aa9d25b5b67", res.MerkleRoot.StringLE())
|
assert.Equal(t, "ae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9", res.MerkleRoot.StringLE())
|
||||||
assert.Equal(t, 1, len(res.Transactions))
|
assert.Equal(t, 1, len(res.Transactions))
|
||||||
assert.Equal(t, "53fe10feb478ba221706d3f43465f8180324626138e4b2745e1f0aa9d25b5b67", res.Transactions[0].Hash().StringLE())
|
assert.Equal(t, "ae63e96d984673b038c83cfcb94323e37bdab29a53921823544b50df9f7edb54", res.Transactions[0].Hash().StringLE())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -154,41 +154,41 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
invoke: func(c *Client) (i interface{}, err error) {
|
invoke: func(c *Client) (i interface{}, err error) {
|
||||||
return c.GetBlockByIndexVerbose(5)
|
return c.GetBlockByIndexVerbose(5)
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"hash":"0x66d1c140fbdc0eaa47e69a6a9c5034ebc3a449db98da565191ab863d1a079906","size":946,"version":0,"nextblockhash":"0xf6749a5eb21273ec67951afd22282f002e605e210678c2fa765dbecf0124bd1a","previousblockhash":"0x8fed18d4cf93e3c1607df1ffcce54a39a25c0bb18f80542ebc7a236a9204aab3","merkleroot":"0x79e5361552be86156c86c000183526f22ce0c8a0be346e692f4b388810275f26","time":1587379353,"index":5,"nonce":"0000000000000457","nextconsensus":"AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU","confirmations":203,"script":{"invocation":"40a6cc2c7fdee4f8fd97f84114d04edda16a37a4c088da9d5be3233e118fccdf73c0305d2cbd15ea0dbcedb594fec3044844e8f59f236ded7fccb1eda2eee2c76740197eba5d648d650ca1d73b8c0a0c7cdc22d31d7b2564764729d271e7ff6378c4f2228f657d65fec530f2af6cdc7af3bc2ab17a7b8175376601fb17ec951faf074038222bb0430f7808d333be3fb8e5b93c490dbb07e6c085350ba64cb7de61127067d1825de30915964dbb345f3b902d61dbf9a294c11ff6459000648f0dc4e66740926854a25b9ea87d7fffe0253bf2bcb3d153434cc0a8ba166136d16aef9a3de70ba3704ba3103a26d01c2bdbeb7262a19bbceab6a7487beba5e55f7ee768a080","verification":"532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae"},"tx":[{"sys_fee":"0","net_fee":"0","txid":"0x79e5361552be86156c86c000183526f22ce0c8a0be346e692f4b388810275f26","size":437,"type":"MinerTransaction","version":0,"nonce":1237,"sender":"AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"40f50121bb6ec9d8e0d1c15eea66b2ff7b51bb1bc4b3da27d9eac1d46b59e6a319bb1db4eb710c7f1931b0c2deaa2389a0fc3fe8c761cec40906b7973450c43173402dc082417a6815e722216de0b857eda6c846bf435088d543d2ab89f1dd92488e87b4d2c6508b0db945cbe6968e85c1c6d57274bfc898e82876c5cb08613da5d64053100f0162a41709a37305c300e7d6ac0d46575aab98dade7375b8d9ca980086594f1288dc68da0e0e42913d1c68024f63442a79c9478971d3ad93c5467ec53040a1c3a772a88b09cba8cc8ec3b46c0c0db6ac86519a7fd7db29b43d34e804a22d8839eaeb35e2a1e05d591fbad4ae290b90c6dc02dddbe28b2b3bf0fec2a337dd","verification":"532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae"}]}]}}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"hash":"0x424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9","size":977,"version":0,"nextblockhash":"0xc2ce96d861414ad229101cc9afaec4ae500f730a2180b54bd14a8dd6147bc8c3","previousblockhash":"0xd32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62","merkleroot":"0xae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9","time":1587726094,"index":5,"consensus_data":{"primary":0,"nonce":"0000000000000457"},"nextconsensus":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","confirmations":203,"script":{"invocation":"0c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c77635","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"},"tx":[{"sys_fee":"0","net_fee":"0","txid":"0xae63e96d984673b038c83cfcb94323e37bdab29a53921823544b50df9f7edb54","size":450,"type":"MinerTransaction","version":0,"nonce":1237,"sender":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"0c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}]}]}}`,
|
||||||
result: func(c *Client) interface{} {
|
result: func(c *Client) interface{} {
|
||||||
hash, err := util.Uint256DecodeStringLE("66d1c140fbdc0eaa47e69a6a9c5034ebc3a449db98da565191ab863d1a079906")
|
hash, err := util.Uint256DecodeStringLE("424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
nextBlockHash, err := util.Uint256DecodeStringLE("f6749a5eb21273ec67951afd22282f002e605e210678c2fa765dbecf0124bd1a")
|
nextBlockHash, err := util.Uint256DecodeStringLE("c2ce96d861414ad229101cc9afaec4ae500f730a2180b54bd14a8dd6147bc8c3")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
prevBlockHash, err := util.Uint256DecodeStringLE("8fed18d4cf93e3c1607df1ffcce54a39a25c0bb18f80542ebc7a236a9204aab3")
|
prevBlockHash, err := util.Uint256DecodeStringLE("d32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
merkleRoot, err := util.Uint256DecodeStringLE("79e5361552be86156c86c000183526f22ce0c8a0be346e692f4b388810275f26")
|
merkleRoot, err := util.Uint256DecodeStringLE("ae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
invScript, err := hex.DecodeString("40a6cc2c7fdee4f8fd97f84114d04edda16a37a4c088da9d5be3233e118fccdf73c0305d2cbd15ea0dbcedb594fec3044844e8f59f236ded7fccb1eda2eee2c76740197eba5d648d650ca1d73b8c0a0c7cdc22d31d7b2564764729d271e7ff6378c4f2228f657d65fec530f2af6cdc7af3bc2ab17a7b8175376601fb17ec951faf074038222bb0430f7808d333be3fb8e5b93c490dbb07e6c085350ba64cb7de61127067d1825de30915964dbb345f3b902d61dbf9a294c11ff6459000648f0dc4e66740926854a25b9ea87d7fffe0253bf2bcb3d153434cc0a8ba166136d16aef9a3de70ba3704ba3103a26d01c2bdbeb7262a19bbceab6a7487beba5e55f7ee768a080")
|
invScript, err := hex.DecodeString("0c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c77635")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
verifScript, err := hex.DecodeString("532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae")
|
verifScript, err := hex.DecodeString("130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
sender, err := address.StringToUint160("AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU")
|
sender, err := address.StringToUint160("Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
txInvScript, err := hex.DecodeString("40f50121bb6ec9d8e0d1c15eea66b2ff7b51bb1bc4b3da27d9eac1d46b59e6a319bb1db4eb710c7f1931b0c2deaa2389a0fc3fe8c761cec40906b7973450c43173402dc082417a6815e722216de0b857eda6c846bf435088d543d2ab89f1dd92488e87b4d2c6508b0db945cbe6968e85c1c6d57274bfc898e82876c5cb08613da5d64053100f0162a41709a37305c300e7d6ac0d46575aab98dade7375b8d9ca980086594f1288dc68da0e0e42913d1c68024f63442a79c9478971d3ad93c5467ec53040a1c3a772a88b09cba8cc8ec3b46c0c0db6ac86519a7fd7db29b43d34e804a22d8839eaeb35e2a1e05d591fbad4ae290b90c6dc02dddbe28b2b3bf0fec2a337dd")
|
txInvScript, err := hex.DecodeString("0c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
txVerifScript, err := hex.DecodeString("532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae")
|
txVerifScript, err := hex.DecodeString("130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -205,16 +205,19 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
_ = tx.Hash()
|
_ = tx.Hash()
|
||||||
return &result.Block{
|
return &result.Block{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
Size: 946,
|
Size: 977,
|
||||||
Version: 0,
|
Version: 0,
|
||||||
NextBlockHash: &nextBlockHash,
|
NextBlockHash: &nextBlockHash,
|
||||||
PreviousBlockHash: prevBlockHash,
|
PreviousBlockHash: prevBlockHash,
|
||||||
MerkleRoot: merkleRoot,
|
MerkleRoot: merkleRoot,
|
||||||
Time: 1587379353,
|
Time: 1587726094,
|
||||||
Index: 5,
|
Index: 5,
|
||||||
Nonce: "0000000000000457",
|
NextConsensus: "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy",
|
||||||
NextConsensus: "AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU",
|
|
||||||
Confirmations: 203,
|
Confirmations: 203,
|
||||||
|
ConsensusData: result.ConsensusData{
|
||||||
|
PrimaryIndex: 0,
|
||||||
|
Nonce: "0000000000000457",
|
||||||
|
},
|
||||||
Script: transaction.Witness{
|
Script: transaction.Witness{
|
||||||
InvocationScript: invScript,
|
InvocationScript: invScript,
|
||||||
VerificationScript: verifScript,
|
VerificationScript: verifScript,
|
||||||
|
@ -232,69 +235,69 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
{
|
{
|
||||||
name: "byHash_positive",
|
name: "byHash_positive",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
hash, err := util.Uint256DecodeStringLE("b84bca7b2d839db01cd70b07050c38051e937f900aa4f7974deb23480c1945d7")
|
hash, err := util.Uint256DecodeStringLE("e9f71b58764157f1e2c3e29f217e654b57956ee7c8a60496b03ea85e39084b42")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return c.GetBlockByHash(hash)
|
return c.GetBlockByHash(hash)
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"000000000c9e819ca13abd194ea86727f8dae2c28634a855836755bde0217125611aefe7675b5bd2a90a1f5e74b2e4386162240318f86534f4d3061722ba78b4fe10fe53a9d49e5e00000000050000005704000000000000d60ac443bb800fb08261e75fa5925d747d48586101fd0401407153238e784d759f1093e5911fcbb07f78af3f83a2159d59511b1c31dd4b70311feb9d63531427ac0e30dc3ae6656adda1f31713a7d56ff68a8764af523776cb4048630138d8d402902b66107ef9a50a227e1be8d8ce148f821e58f45430e59b8c034f1b5ed8208f7ce9711942405bb991d4e69232235bafa5476a8f30b92ac7e840947723eafcdfa2e9d75b551b5fc72bdb300cf541d84db5be4f2a5c33d45b0e3ae35a18c33af988c88dd201c823c15fced52eeed66d7defa3fcf7ea1587e8851c40365d8fdf714453d48f030cf3f7744b57d2cd35ad07a7980b58718e3da9e4dfe466f2e1089e8123dfc5d8d6fe679627ae78aa4cb4986cb4805d78becc009544c594534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb010000d5040000d60ac443bb800fb08261e75fa5925d747d4858610500000000000001fd040140947358ca2dd7543c3ff3f6ea1389a72c3d5ee99f47a9d0ef70bd84a9f57384e76271efc682f6741568c55907b1794b9f520f7d35f39382303bf0206945b5009a409f467419a886aebe6b482e6d5787981d98b58b82959a2858045bf5683665a5c25c502481b2d9655c902c5dcc147546bed58175c2ed16f328cc21e999e19741554063cab34f1613932947a1c346416b12b1ca724198016acc5fd760597539eed74f2069cfe2a8383e99595aefa3234d79d64a39e3f4c64e8cea800469a6f790999c408e2438fab244bdb79e67f6dab9cde0063e523bd0c175657a66e84897cd15eec8bf358661666679bf50334664872616faa366825f36873b16dd2add64c418cd5794534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb"}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"0000000062af8cd56d179044215cc8611f75bd96d896f1026c5b42994ae7707df8d82bd3c9f774f449fec7135b506faffaaeee603e2b82e01dec7d0f706789aa1bb983ae0ec7a25e0000000005000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c7763594130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb020057040000000000000000d5040000e903736ceceeceae1806eee0e3ec61e7cce476ce0500000000000001fd08010c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}`,
|
||||||
result: func(c *Client) interface{} { return &block.Block{} },
|
result: func(c *Client) interface{} { return &block.Block{} },
|
||||||
check: func(t *testing.T, c *Client, result interface{}) {
|
check: func(t *testing.T, c *Client, result interface{}) {
|
||||||
res, ok := result.(*block.Block)
|
res, ok := result.(*block.Block)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
assert.Equal(t, uint32(0), res.Version)
|
assert.Equal(t, uint32(0), res.Version)
|
||||||
assert.Equal(t, "d745190c4823eb4d97f7a40a907f931e05380c05070bd71cb09d832d7bca4bb8", res.Hash().StringLE())
|
assert.Equal(t, "424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9", res.Hash().StringLE())
|
||||||
assert.Equal(t, "e7ef1a61257121e0bd55678355a83486c2e2daf82767a84e19bd3aa19c819e0c", res.PrevHash.StringLE())
|
assert.Equal(t, "d32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62", res.PrevHash.StringLE())
|
||||||
assert.Equal(t, "53fe10feb478ba221706d3f43465f8180324626138e4b2745e1f0aa9d25b5b67", res.MerkleRoot.StringLE())
|
assert.Equal(t, "ae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9", res.MerkleRoot.StringLE())
|
||||||
assert.Equal(t, 1, len(res.Transactions))
|
assert.Equal(t, 1, len(res.Transactions))
|
||||||
assert.Equal(t, "53fe10feb478ba221706d3f43465f8180324626138e4b2745e1f0aa9d25b5b67", res.Transactions[0].Hash().StringLE())
|
assert.Equal(t, "ae63e96d984673b038c83cfcb94323e37bdab29a53921823544b50df9f7edb54", res.Transactions[0].Hash().StringLE())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "byHash_verbose_positive",
|
name: "byHash_verbose_positive",
|
||||||
invoke: func(c *Client) (i interface{}, err error) {
|
invoke: func(c *Client) (i interface{}, err error) {
|
||||||
hash, err := util.Uint256DecodeStringLE("0699071a3d86ab915156da98db49a4c3eb34509c6a9ae647aa0edcfb40c1d166")
|
hash, err := util.Uint256DecodeStringLE("e9f71b58764157f1e2c3e29f217e654b57956ee7c8a60496b03ea85e39084b42")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return c.GetBlockByHashVerbose(hash)
|
return c.GetBlockByHashVerbose(hash)
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"hash":"0x66d1c140fbdc0eaa47e69a6a9c5034ebc3a449db98da565191ab863d1a079906","size":946,"version":0,"nextblockhash":"0xf6749a5eb21273ec67951afd22282f002e605e210678c2fa765dbecf0124bd1a","previousblockhash":"0x8fed18d4cf93e3c1607df1ffcce54a39a25c0bb18f80542ebc7a236a9204aab3","merkleroot":"0x79e5361552be86156c86c000183526f22ce0c8a0be346e692f4b388810275f26","time":1587379353,"index":5,"nonce":"0000000000000457","nextconsensus":"AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU","confirmations":203,"script":{"invocation":"40a6cc2c7fdee4f8fd97f84114d04edda16a37a4c088da9d5be3233e118fccdf73c0305d2cbd15ea0dbcedb594fec3044844e8f59f236ded7fccb1eda2eee2c76740197eba5d648d650ca1d73b8c0a0c7cdc22d31d7b2564764729d271e7ff6378c4f2228f657d65fec530f2af6cdc7af3bc2ab17a7b8175376601fb17ec951faf074038222bb0430f7808d333be3fb8e5b93c490dbb07e6c085350ba64cb7de61127067d1825de30915964dbb345f3b902d61dbf9a294c11ff6459000648f0dc4e66740926854a25b9ea87d7fffe0253bf2bcb3d153434cc0a8ba166136d16aef9a3de70ba3704ba3103a26d01c2bdbeb7262a19bbceab6a7487beba5e55f7ee768a080","verification":"532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae"},"tx":[{"sys_fee":"0","net_fee":"0","txid":"0x79e5361552be86156c86c000183526f22ce0c8a0be346e692f4b388810275f26","size":437,"type":"MinerTransaction","version":0,"nonce":1237,"sender":"AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"40f50121bb6ec9d8e0d1c15eea66b2ff7b51bb1bc4b3da27d9eac1d46b59e6a319bb1db4eb710c7f1931b0c2deaa2389a0fc3fe8c761cec40906b7973450c43173402dc082417a6815e722216de0b857eda6c846bf435088d543d2ab89f1dd92488e87b4d2c6508b0db945cbe6968e85c1c6d57274bfc898e82876c5cb08613da5d64053100f0162a41709a37305c300e7d6ac0d46575aab98dade7375b8d9ca980086594f1288dc68da0e0e42913d1c68024f63442a79c9478971d3ad93c5467ec53040a1c3a772a88b09cba8cc8ec3b46c0c0db6ac86519a7fd7db29b43d34e804a22d8839eaeb35e2a1e05d591fbad4ae290b90c6dc02dddbe28b2b3bf0fec2a337dd","verification":"532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae"}]}]}}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"hash":"0x424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9","size":977,"version":0,"nextblockhash":"0xc2ce96d861414ad229101cc9afaec4ae500f730a2180b54bd14a8dd6147bc8c3","previousblockhash":"0xd32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62","merkleroot":"0xae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9","time":1587726094,"index":5,"consensus_data":{"primary":0,"nonce":"0000000000000457"},"nextconsensus":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","confirmations":203,"script":{"invocation":"0c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c77635","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"},"tx":[{"sys_fee":"0","net_fee":"0","txid":"0xae63e96d984673b038c83cfcb94323e37bdab29a53921823544b50df9f7edb54","size":450,"type":"MinerTransaction","version":0,"nonce":1237,"sender":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"0c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}]}]}}`,
|
||||||
result: func(c *Client) interface{} {
|
result: func(c *Client) interface{} {
|
||||||
hash, err := util.Uint256DecodeStringLE("66d1c140fbdc0eaa47e69a6a9c5034ebc3a449db98da565191ab863d1a079906")
|
hash, err := util.Uint256DecodeStringLE("424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
nextBlockHash, err := util.Uint256DecodeStringLE("f6749a5eb21273ec67951afd22282f002e605e210678c2fa765dbecf0124bd1a")
|
nextBlockHash, err := util.Uint256DecodeStringLE("c2ce96d861414ad229101cc9afaec4ae500f730a2180b54bd14a8dd6147bc8c3")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
prevBlockHash, err := util.Uint256DecodeStringLE("8fed18d4cf93e3c1607df1ffcce54a39a25c0bb18f80542ebc7a236a9204aab3")
|
prevBlockHash, err := util.Uint256DecodeStringLE("d32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
merkleRoot, err := util.Uint256DecodeStringLE("79e5361552be86156c86c000183526f22ce0c8a0be346e692f4b388810275f26")
|
merkleRoot, err := util.Uint256DecodeStringLE("ae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
invScript, err := hex.DecodeString("40a6cc2c7fdee4f8fd97f84114d04edda16a37a4c088da9d5be3233e118fccdf73c0305d2cbd15ea0dbcedb594fec3044844e8f59f236ded7fccb1eda2eee2c76740197eba5d648d650ca1d73b8c0a0c7cdc22d31d7b2564764729d271e7ff6378c4f2228f657d65fec530f2af6cdc7af3bc2ab17a7b8175376601fb17ec951faf074038222bb0430f7808d333be3fb8e5b93c490dbb07e6c085350ba64cb7de61127067d1825de30915964dbb345f3b902d61dbf9a294c11ff6459000648f0dc4e66740926854a25b9ea87d7fffe0253bf2bcb3d153434cc0a8ba166136d16aef9a3de70ba3704ba3103a26d01c2bdbeb7262a19bbceab6a7487beba5e55f7ee768a080")
|
invScript, err := hex.DecodeString("0c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c77635")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
verifScript, err := hex.DecodeString("532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae")
|
verifScript, err := hex.DecodeString("130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
sender, err := address.StringToUint160("AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU")
|
sender, err := address.StringToUint160("Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
txInvScript, err := hex.DecodeString("40f50121bb6ec9d8e0d1c15eea66b2ff7b51bb1bc4b3da27d9eac1d46b59e6a319bb1db4eb710c7f1931b0c2deaa2389a0fc3fe8c761cec40906b7973450c43173402dc082417a6815e722216de0b857eda6c846bf435088d543d2ab89f1dd92488e87b4d2c6508b0db945cbe6968e85c1c6d57274bfc898e82876c5cb08613da5d64053100f0162a41709a37305c300e7d6ac0d46575aab98dade7375b8d9ca980086594f1288dc68da0e0e42913d1c68024f63442a79c9478971d3ad93c5467ec53040a1c3a772a88b09cba8cc8ec3b46c0c0db6ac86519a7fd7db29b43d34e804a22d8839eaeb35e2a1e05d591fbad4ae290b90c6dc02dddbe28b2b3bf0fec2a337dd")
|
txInvScript, err := hex.DecodeString("0c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
txVerifScript, err := hex.DecodeString("532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae")
|
txVerifScript, err := hex.DecodeString("130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -311,16 +314,19 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
_ = tx.Hash()
|
_ = tx.Hash()
|
||||||
return &result.Block{
|
return &result.Block{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
Size: 946,
|
Size: 977,
|
||||||
Version: 0,
|
Version: 0,
|
||||||
NextBlockHash: &nextBlockHash,
|
NextBlockHash: &nextBlockHash,
|
||||||
PreviousBlockHash: prevBlockHash,
|
PreviousBlockHash: prevBlockHash,
|
||||||
MerkleRoot: merkleRoot,
|
MerkleRoot: merkleRoot,
|
||||||
Time: 1587379353,
|
Time: 1587726094,
|
||||||
Index: 5,
|
Index: 5,
|
||||||
Nonce: "0000000000000457",
|
NextConsensus: "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy",
|
||||||
NextConsensus: "AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU",
|
|
||||||
Confirmations: 203,
|
Confirmations: 203,
|
||||||
|
ConsensusData: result.ConsensusData{
|
||||||
|
PrimaryIndex: 0,
|
||||||
|
Nonce: "0000000000000457",
|
||||||
|
},
|
||||||
Script: transaction.Witness{
|
Script: transaction.Witness{
|
||||||
InvocationScript: invScript,
|
InvocationScript: invScript,
|
||||||
VerificationScript: verifScript,
|
VerificationScript: verifScript,
|
||||||
|
@ -368,21 +374,21 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
hash, err := util.Uint256DecodeStringLE("cac0ebfcf1230d0cd236f333dc659b232da612e7ee42bd80f9e6c8d0ce2fb542")
|
hash, err := util.Uint256DecodeStringLE("68e4bd688b852e807eef13a0ff7da7b02223e359a35153667e88f9cb4a3b0801")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return c.GetBlockHeader(hash)
|
return c.GetBlockHeader(hash)
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"0000000098166844503a270bf532addc3db1a30e22b5336594ed8944fceaaf8fe697013414aa46a5e3e62056c842d54ea5ba480fc448c498989f505bcae9ae4364436b9da5d49e5e00000000010000005704000000000000d60ac443bb800fb08261e75fa5925d747d48586101fd040140519e5dfec4f07533853ca092139070fb6f033f8ab03b226948ee35910767a2ec426ad16d70e6aaf6e70ba256c829c963efc61b450690f9f4c022ec345f4b698240527d91d454a488419f724f51f44b33f162a4c8dfe84775e3e178abe254c728fda5a81915b3fbd9d41c0609f3cd576ba65b767753b2d52e4f96ce1a9b1cdb1e364021d2d03a1b57ab5bb50ac19679f9543f10c8873ef9a8d4c236f9e022c0a60f684b78bf56bd2b5f82d0a8ed091cadd2f29a16a7e9f48f3feb723dcb7f26470f5e40f447d13062ab7ec4669b82d0da2d4e0165756b30c5f6b734cb2049d91ae0f8ab85ab52f476d825ea12f26cfaf6c8d6c662bb7e3442130785b2d12e3398ac204f94534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb00"}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"00000000d039da5e49d63eb0533437d24ff8ceb6aeacf88680599c39f0ffca8948dfcdb94a3def1fca91cf45d69358414e3be77f7621e557f4cebbdb79a47d3cf56ac007f920a05e0000000001000000d60ac443bb800fb08261e75fa5925d747d48586101fd04014055041db6a59c99ab98137cc57e1e56a0a89856a311b2d2fc0aec76ec714c7616edc8fc5c9b81b27f25b7db1a61f64be0730a9cc103efcea1195cc3fe55843e264027e49c647f48bb08d3c32b79ee3432005ea577d7e497f78b46f1e81858848f961b557fb42a92e8eb4433fed203c917cbebb2138a31ed86750fb769d1e70956c0404c20054aa8bd45b520cba9410a9dd6c256481066bb657d7793fbba5551898c91b6dde81285fac841753ccfdd3193d08f19d5431313fa0d926ca965072a5fa3384026b0705078409bcc62fb98bb985edc387edeaaeba37bb7642d88a90762b2c2a62d9b61d53c097d548a368e450c4d995a178d5af28d4c93698233c52de05e3f0094534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb00"}`,
|
||||||
result: func(c *Client) interface{} { return &block.Header{} },
|
result: func(c *Client) interface{} { return &block.Header{} },
|
||||||
check: func(t *testing.T, c *Client, result interface{}) {
|
check: func(t *testing.T, c *Client, result interface{}) {
|
||||||
res, ok := result.(*block.Header)
|
res, ok := result.(*block.Header)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
assert.Equal(t, uint32(0), res.Version)
|
assert.Equal(t, uint32(0), res.Version)
|
||||||
assert.Equal(t, "cac0ebfcf1230d0cd236f333dc659b232da612e7ee42bd80f9e6c8d0ce2fb542", res.Hash().StringLE())
|
assert.Equal(t, "68e4bd688b852e807eef13a0ff7da7b02223e359a35153667e88f9cb4a3b0801", res.Hash().StringLE())
|
||||||
assert.Equal(t, "340197e68fafeafc4489ed946533b5220ea3b13ddcad32f50b273a5044681698", res.PrevHash.StringLE())
|
assert.Equal(t, "b9cddf4889cafff0399c598086f8acaeb6cef84fd2373453b03ed6495eda39d0", res.PrevHash.StringLE())
|
||||||
assert.Equal(t, "9d6b436443aee9ca5b509f9898c448c40f48baa54ed542c85620e6e3a546aa14", res.MerkleRoot.StringLE())
|
assert.Equal(t, "07c06af53c7da479dbbbcef457e521767fe73b4e415893d645cf91ca1fef3d4a", res.MerkleRoot.StringLE())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -429,7 +435,6 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
MerkleRoot: merkleRoot,
|
MerkleRoot: merkleRoot,
|
||||||
Timestamp: 1541215200,
|
Timestamp: 1541215200,
|
||||||
Index: 1,
|
Index: 1,
|
||||||
Nonce: "51b484a2fe49ed4d",
|
|
||||||
NextConsensus: "AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU",
|
NextConsensus: "AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU",
|
||||||
Confirmations: 20061,
|
Confirmations: 20061,
|
||||||
Script: transaction.Witness{
|
Script: transaction.Witness{
|
||||||
|
|
|
@ -27,6 +27,12 @@ type (
|
||||||
NetFee util.Fixed8 `json:"net_fee"`
|
NetFee util.Fixed8 `json:"net_fee"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConsensusData is a wrapper for block.ConsensusData
|
||||||
|
ConsensusData struct {
|
||||||
|
PrimaryIndex uint32 `json:"primary"`
|
||||||
|
Nonce string `json:"nonce"`
|
||||||
|
}
|
||||||
|
|
||||||
// Block wrapper used for the representation of
|
// Block wrapper used for the representation of
|
||||||
// block.Block / block.Base on the RPC Server.
|
// block.Block / block.Base on the RPC Server.
|
||||||
Block struct {
|
Block struct {
|
||||||
|
@ -38,7 +44,7 @@ type (
|
||||||
MerkleRoot util.Uint256 `json:"merkleroot"`
|
MerkleRoot util.Uint256 `json:"merkleroot"`
|
||||||
Time uint64 `json:"time"`
|
Time uint64 `json:"time"`
|
||||||
Index uint32 `json:"index"`
|
Index uint32 `json:"index"`
|
||||||
Nonce string `json:"nonce"`
|
ConsensusData ConsensusData `json:"consensus_data"`
|
||||||
NextConsensus string `json:"nextconsensus"`
|
NextConsensus string `json:"nextconsensus"`
|
||||||
|
|
||||||
Confirmations uint32 `json:"confirmations"`
|
Confirmations uint32 `json:"confirmations"`
|
||||||
|
@ -59,9 +65,12 @@ func NewBlock(b *block.Block, chain blockchainer.Blockchainer) Block {
|
||||||
MerkleRoot: b.MerkleRoot,
|
MerkleRoot: b.MerkleRoot,
|
||||||
Time: b.Timestamp,
|
Time: b.Timestamp,
|
||||||
Index: b.Index,
|
Index: b.Index,
|
||||||
Nonce: fmt.Sprintf("%016x", b.ConsensusData),
|
ConsensusData: ConsensusData{
|
||||||
NextConsensus: address.Uint160ToString(b.NextConsensus),
|
PrimaryIndex: b.ConsensusData.PrimaryIndex,
|
||||||
Confirmations: chain.BlockHeight() - b.Index - 1,
|
Nonce: fmt.Sprintf("%016x", b.ConsensusData.Nonce),
|
||||||
|
},
|
||||||
|
NextConsensus: address.Uint160ToString(b.NextConsensus),
|
||||||
|
Confirmations: chain.BlockHeight() - b.Index - 1,
|
||||||
|
|
||||||
Script: b.Script,
|
Script: b.Script,
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package result
|
package result
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
@ -22,7 +20,6 @@ type (
|
||||||
MerkleRoot util.Uint256 `json:"merkleroot"`
|
MerkleRoot util.Uint256 `json:"merkleroot"`
|
||||||
Timestamp uint64 `json:"time"`
|
Timestamp uint64 `json:"time"`
|
||||||
Index uint32 `json:"index"`
|
Index uint32 `json:"index"`
|
||||||
Nonce string `json:"nonce"`
|
|
||||||
NextConsensus string `json:"nextconsensus"`
|
NextConsensus string `json:"nextconsensus"`
|
||||||
Script transaction.Witness `json:"script"`
|
Script transaction.Witness `json:"script"`
|
||||||
Confirmations uint32 `json:"confirmations"`
|
Confirmations uint32 `json:"confirmations"`
|
||||||
|
@ -40,7 +37,6 @@ func NewHeader(h *block.Header, chain blockchainer.Blockchainer) Header {
|
||||||
MerkleRoot: h.MerkleRoot,
|
MerkleRoot: h.MerkleRoot,
|
||||||
Timestamp: h.Timestamp,
|
Timestamp: h.Timestamp,
|
||||||
Index: h.Index,
|
Index: h.Index,
|
||||||
Nonce: strconv.FormatUint(h.ConsensusData, 16),
|
|
||||||
NextConsensus: address.Uint160ToString(h.NextConsensus),
|
NextConsensus: address.Uint160ToString(h.NextConsensus),
|
||||||
Script: h.Script,
|
Script: h.Script,
|
||||||
Confirmations: chain.BlockHeight() - h.Index + 1,
|
Confirmations: chain.BlockHeight() - h.Index + 1,
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -967,7 +966,6 @@ func TestRPC(t *testing.T) {
|
||||||
MerkleRoot: hdr.MerkleRoot,
|
MerkleRoot: hdr.MerkleRoot,
|
||||||
Timestamp: hdr.Timestamp,
|
Timestamp: hdr.Timestamp,
|
||||||
Index: hdr.Index,
|
Index: hdr.Index,
|
||||||
Nonce: strconv.FormatUint(hdr.ConsensusData, 16),
|
|
||||||
NextConsensus: address.Uint160ToString(hdr.NextConsensus),
|
NextConsensus: address.Uint160ToString(hdr.NextConsensus),
|
||||||
Script: hdr.Script,
|
Script: hdr.Script,
|
||||||
Confirmations: e.chain.BlockHeight() - hdr.Index + 1,
|
Confirmations: e.chain.BlockHeight() - hdr.Index + 1,
|
||||||
|
@ -1051,10 +1049,13 @@ func newBlock(t *testing.T, bc blockchainer.Blockchainer, index uint32, txs ...*
|
||||||
PrevHash: hdr.Hash(),
|
PrevHash: hdr.Hash(),
|
||||||
Timestamp: (uint64(time.Now().UTC().Unix()) + uint64(hdr.Index)) * 1000,
|
Timestamp: (uint64(time.Now().UTC().Unix()) + uint64(hdr.Index)) * 1000,
|
||||||
Index: hdr.Index + index,
|
Index: hdr.Index + index,
|
||||||
ConsensusData: 1111,
|
|
||||||
NextConsensus: witness.ScriptHash(),
|
NextConsensus: witness.ScriptHash(),
|
||||||
Script: witness,
|
Script: witness,
|
||||||
},
|
},
|
||||||
|
ConsensusData: block.ConsensusData{
|
||||||
|
PrimaryIndex: 0,
|
||||||
|
Nonce: 1111,
|
||||||
|
},
|
||||||
Transactions: txs,
|
Transactions: txs,
|
||||||
}
|
}
|
||||||
_ = b.RebuildMerkleRoot()
|
_ = b.RebuildMerkleRoot()
|
||||||
|
|
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
Binary file not shown.
Loading…
Reference in a new issue