From f63d347e44c3572f102ff021bf6febd648818034 Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Fri, 3 Aug 2018 15:49:10 -0400 Subject: [PATCH 1/7] Moved setprods structs. Re-added indented debug output --- decoder.go | 20 +++++++++++++------- decoder_test.go | 1 - system/setprods.go | 15 ++++++++++++++- system/types.go | 11 ----------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/decoder.go b/decoder.go index b9744350..6310f775 100644 --- a/decoder.go +++ b/decoder.go @@ -69,20 +69,22 @@ type Decoder struct { decodeActions bool } -//var prefix = make([]string, 0) +var prefix = make([]string, 0) var Debug bool var print = func(s string) { if Debug { - //for _, s := range prefix { - //fmt.Print(s) - //} + for _, s := range prefix { + fmt.Print(s) + } fmt.Print(s) } } var println = func(args ...interface{}) { - print(fmt.Sprintf("%s\n", args...)) + if Debug { + print(fmt.Sprintf("%s\n", args...)) + } } func NewDecoder(data []byte) *Decoder { @@ -374,7 +376,9 @@ func (d *Decoder) Decode(v interface{}) (err error) { func (d *Decoder) decodeStruct(v interface{}, t reflect.Type, rv reflect.Value) (err error) { l := rv.NumField() - //prefix = append(prefix, " ") + if Debug { + prefix = append(prefix, " ") + } for i := 0; i < l; i++ { if tag := t.Field(i).Tag.Get("eos"); tag == "-" { @@ -389,7 +393,9 @@ func (d *Decoder) decodeStruct(v interface{}, t reflect.Type, rv reflect.Value) } } } - //prefix = prefix[:len(prefix)-1] + if Debug { + prefix = prefix[:len(prefix)-1] + } return } diff --git a/decoder_test.go b/decoder_test.go index 0d751fe3..fc2c19d3 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -455,7 +455,6 @@ func TestDecoder_Decode_Slice_Err(t *testing.T) { decoder = NewDecoder(buf.Bytes()) err = decoder.Decode(&s) assert.Equal(t, err, ErrVarIntBufferSize) - } type structWithInvalidType struct { diff --git a/system/setprods.go b/system/setprods.go index f740a6b3..7bfbdfab 100644 --- a/system/setprods.go +++ b/system/setprods.go @@ -1,6 +1,9 @@ package system -import eos "github.com/eoscanada/eos-go" +import ( + eos "github.com/eoscanada/eos-go" + "github.com/eoscanada/eos-go/ecc" +) // NewSetPriv returns a `setpriv` action that lives on the // `eosio.bios` contract. It should exist only when booting a new @@ -19,3 +22,13 @@ func NewSetProds(producers []ProducerKey) *eos.Action { } return a } + +// SetProds is present in `eosio.bios` contract. Used only at boot time. +type SetProds struct { + Schedule []ProducerKey `json:"schedule"` +} + +type ProducerKey struct { + ProducerName eos.AccountName `json:"producer_name"` + BlockSigningKey ecc.PublicKey `json:"block_signing_key"` +} diff --git a/system/types.go b/system/types.go index 7b6d0118..9e152cb1 100644 --- a/system/types.go +++ b/system/types.go @@ -2,19 +2,8 @@ package system import ( eos "github.com/eoscanada/eos-go" - "github.com/eoscanada/eos-go/ecc" ) -// SetProds is present in `eosio.bios` contract. Used only at boot time. -type SetProds struct { - Schedule []ProducerKey `json:"schedule"` -} - -type ProducerKey struct { - ProducerName eos.AccountName `json:"producer_name"` - BlockSigningKey ecc.PublicKey `json:"block_signing_key"` -} - // BlockchainParameters are all the params we can set through `setparams`. type BlockchainParameters struct { MaxBlockNetUsage uint64 `json:"max_block_net_usage"` From d3cd76c9018a94c1a67bce795216e1231332805e Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Fri, 3 Aug 2018 16:02:22 -0400 Subject: [PATCH 2/7] Added UnpackBare --- transaction.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/transaction.go b/transaction.go index 4b8d4c59..ed3362e2 100644 --- a/transaction.go +++ b/transaction.go @@ -202,7 +202,19 @@ func (p *PackedTransaction) ID() SHA256Bytes { return h.Sum(nil) } +// Unpack decodes the bytestream of the transaction, and attempts to +// decode the registered actions. func (p *PackedTransaction) Unpack() (signedTx *SignedTransaction, err error) { + return p.unpack(false) +} + +// UnpackBare decodes the transcation payload, but doesn't decode the +// nested action data structure. See also `Unpack`. +func (p *PackedTransaction) UnpackBare() (signedTx *SignedTransaction, err error) { + return p.unpack(true) +} + +func (p *PackedTransaction) unpack(bare bool) (signedTx *SignedTransaction, err error) { var txReader io.Reader txReader = bytes.NewBuffer(p.PackedTransaction) @@ -229,6 +241,7 @@ func (p *PackedTransaction) Unpack() (signedTx *SignedTransaction, err error) { return nil, fmt.Errorf("unpack read all, %s", err) } decoder := NewDecoder(data) + decoder.DecodeActions(!bare) var tx Transaction err = decoder.Decode(&tx) From 7cabff2812d4745066b2aeea8c2744fb8b736608 Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Sun, 12 Aug 2018 09:00:00 -0400 Subject: [PATCH 3/7] Added `location` to regproducer. --- system/regproducer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/regproducer.go b/system/regproducer.go index 715bf7ed..b1ff4e92 100644 --- a/system/regproducer.go +++ b/system/regproducer.go @@ -7,7 +7,7 @@ import ( // NewRegProducer returns a `regproducer` action that lives on the // `eosio.system` contract. -func NewRegProducer(producer eos.AccountName, producerKey ecc.PublicKey, url string) *eos.Action { +func NewRegProducer(producer eos.AccountName, producerKey ecc.PublicKey, url string, location uint16) *eos.Action { return &eos.Action{ Account: AN("eosio"), Name: ActN("regproducer"), @@ -18,7 +18,7 @@ func NewRegProducer(producer eos.AccountName, producerKey ecc.PublicKey, url str Producer: producer, ProducerKey: producerKey, URL: url, - Location: 0, + Location: location, }), } } From 47daef61513d2c76b1333f28000fac6216439cfe Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Sun, 12 Aug 2018 09:01:37 -0400 Subject: [PATCH 4/7] Added BlockID reader. --- types.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/types.go b/types.go index 961e6602..6826779d 100644 --- a/types.go +++ b/types.go @@ -1,6 +1,7 @@ package eos import ( + "encoding/binary" "encoding/hex" "encoding/json" "errors" @@ -429,6 +430,19 @@ func (t *Tstamp) UnmarshalJSON(data []byte) (err error) { return nil } +type BlockID string + +func (b BlockID) BlockNum() uint32 { + if len(b) < 8 { + return 0 + } + bin, err := hex.DecodeString(string(b)[:8]) + if err != nil { + return 0 + } + return binary.BigEndian.Uint32(bin) +} + type BlockTimestamp struct { time.Time } From e5c48cf5db945888a2a15aa83dafc89ce0dfeec4 Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Wed, 15 Aug 2018 15:12:56 -0400 Subject: [PATCH 5/7] Added top-level BlockNum function, to extract block num from a block ID. --- types.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/types.go b/types.go index 6826779d..fef99c89 100644 --- a/types.go +++ b/types.go @@ -430,13 +430,12 @@ func (t *Tstamp) UnmarshalJSON(data []byte) (err error) { return nil } -type BlockID string - -func (b BlockID) BlockNum() uint32 { - if len(b) < 8 { +// BlockNum extracts the block number (or height) from a hex-encoded block ID. +func BlockNum(blockID string) uint32 { + if len(blockID) < 8 { return 0 } - bin, err := hex.DecodeString(string(b)[:8]) + bin, err := hex.DecodeString(blockID[:8]) if err != nil { return 0 } From 028ea8d5820a170986985b2b20ea5cf645d06695 Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Thu, 16 Aug 2018 01:27:22 -0400 Subject: [PATCH 6/7] Allow an empty NewTransaction not to crash. --- transaction.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/transaction.go b/transaction.go index ed3362e2..155eeda2 100644 --- a/transaction.go +++ b/transaction.go @@ -76,6 +76,9 @@ func (tx *Transaction) Fill(headBlockID SHA256Bytes, delaySecs, maxNetUsageWords } func (tx *Transaction) setRefBlock(blockID []byte) { + if len(blockID) == 0 { + return + } tx.RefBlockNum = uint16(binary.BigEndian.Uint32(blockID[:4])) tx.RefBlockPrefix = binary.LittleEndian.Uint32(blockID[8:16]) } From 3eb310aa4b932ae22c047eb9924ce4141976ea7d Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Thu, 16 Aug 2018 10:44:43 -0400 Subject: [PATCH 7/7] Added server_version_string --- responses.go | 1 + 1 file changed, 1 insertion(+) diff --git a/responses.go b/responses.go index 8b21f27b..1d6257a1 100644 --- a/responses.go +++ b/responses.go @@ -40,6 +40,7 @@ type InfoResp struct { VirtualBlockNetLimit JSONInt64 `json:"virtual_block_net_limit"` BlockCPULimit JSONInt64 `json:"block_cpu_limit"` BlockNetLimit JSONInt64 `json:"block_net_limit"` + ServerVersionString string `json:"server_version_string"` } type BlockResp struct {