Skip to content

Commit

Permalink
Merge branch 'master' of github.com:eoscanada/eos-go
Browse files Browse the repository at this point in the history
  • Loading branch information
dix975 committed Aug 21, 2018
2 parents f297a12 + 3eb310a commit 1b5fa8b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 22 deletions.
20 changes: 13 additions & 7 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 == "-" {
Expand All @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions system/regproducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -18,7 +18,7 @@ func NewRegProducer(producer eos.AccountName, producerKey ecc.PublicKey, url str
Producer: producer,
ProducerKey: producerKey,
URL: url,
Location: 0,
Location: location,
}),
}
}
Expand Down
15 changes: 14 additions & 1 deletion system/setprods.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"`
}
11 changes: 0 additions & 11 deletions system/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
16 changes: 16 additions & 0 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down Expand Up @@ -202,7 +205,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)

Expand All @@ -229,6 +244,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)
Expand Down
13 changes: 13 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eos

import (
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
Expand Down Expand Up @@ -429,6 +430,18 @@ func (t *Tstamp) UnmarshalJSON(data []byte) (err error) {
return nil
}

// 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(blockID[:8])
if err != nil {
return 0
}
return binary.BigEndian.Uint32(bin)
}

type BlockTimestamp struct {
time.Time
}
Expand Down

0 comments on commit 1b5fa8b

Please sign in to comment.