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 Jul 23, 2018
2 parents 2d8665c + f155f22 commit ec64637
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 15 deletions.
5 changes: 5 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ func (api *API) GetTransaction(id string) (out *TransactionResp, err error) {
return
}

func (api *API) GetTransactionRaw(id string) (out json.RawMessage, err error) {
err = api.call("history", "get_transaction", M{"id": id}, &out)
return
}

func (api *API) GetTransactions(name AccountName) (out *TransactionsResp, err error) {
err = api.call("account_history", "get_transactions", M{"account_name": name}, &out)
return
Expand Down
34 changes: 25 additions & 9 deletions p2ptypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,33 @@ func (t *TransactionWithID) UnmarshalJSON(data []byte) error {
return fmt.Errorf("expected two params for TransactionWithID, got %d", len(in))
}

// ignore the ID field right now..
err = json.Unmarshal(in[1], &packed)
if err != nil {
return err
}
typ := string(in[0])
switch typ {
case "0":
var s string
if err := json.Unmarshal(in[1], &s); err != nil {
return err
}

*t = TransactionWithID{
ID: packed.ID(),
Packed: &packed,
}
*t = TransactionWithID{}
if err := json.Unmarshal(in[1], &t.ID); err != nil {
return err
}
case "1":

// ignore the ID field right now..
err = json.Unmarshal(in[1], &packed)
if err != nil {
return err
}

*t = TransactionWithID{
ID: packed.ID(),
Packed: &packed,
}
default:
return fmt.Errorf("unsupported multi-variant trx serialization type from C++ code into Go: %q", typ)
}
return nil
}

Expand Down
5 changes: 2 additions & 3 deletions responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import (

"encoding/json"

eos "github.com/eoscanada/eos-go"
"github.com/stretchr/testify/assert"
)

func TestUnmarshalAccountResp(t *testing.T) {
resp := &eos.AccountResp{}
resp := &AccountResp{}

err := json.Unmarshal([]byte(jsonData), resp)
assert.NoError(t, err)

assert.Equal(t, eos.AccountName("eosriobrazil"), resp.AccountName)
assert.Equal(t, AccountName("eosriobrazil"), resp.AccountName)
}

var jsonData = `{
Expand Down
1 change: 1 addition & 0 deletions system/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {
// eos.RegisterAction(AN("eosio"), ActN("nonce"), &Nonce{})
eos.RegisterAction(AN("eosio"), ActN("sellram"), SellRAM{})
eos.RegisterAction(AN("eosio"), ActN("updateauth"), UpdateAuth{})
eos.RegisterAction(AN("eosio"), ActN("setramrate"), SetRAMRate{})
}

var AN = eos.AN
Expand Down
4 changes: 2 additions & 2 deletions system/newaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestActionNewAccount(t *testing.T) {
buf, err = json.Marshal(a.ActionData.Data)
assert.NoError(t, err)

assert.Equal(t, "{\"creator\":\"eosio\",\"name\":\"abourget\",\"owner\":{\"threshold\":1,\"keys\":[{\"key\":\"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\",\"weight\":1}],\"accounts\":null,\"waits\":null},\"active\":{\"threshold\":1,\"keys\":[{\"key\":\"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\",\"weight\":1}],\"accounts\":null,\"waits\":null}}", string(buf))
assert.Equal(t, "{\"creator\":\"eosio\",\"name\":\"abourget\",\"owner\":{\"threshold\":1,\"keys\":[{\"key\":\"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\",\"weight\":1}]},\"active\":{\"threshold\":1,\"keys\":[{\"key\":\"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\",\"weight\":1}]}}", string(buf))
// 00096e88 0000 0000 00000000 00 00 00 00 01 0000000000ea3055

// WUTz that ?
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestMarshalTransactionAndSigned(t *testing.T) {

buf, err = json.Marshal(a)
assert.NoError(t, err)
assert.Equal(t, `{"account":"eosio","name":"newaccount","authorization":[{"actor":"eosio","permission":"active"}],"data":"0000000000ea305500000059b1abe931000000000000000000000000000000000000"}`, string(buf))
assert.Equal(t, `{"account":"eosio","name":"newaccount","authorization":[{"actor":"eosio","permission":"active"}],"data":"0000000000ea305500000059b1abe9310000000000000000000000000000"}`, string(buf))
}

func TestMarshalTransactionAndPack(t *testing.T) {
Expand Down
62 changes: 61 additions & 1 deletion system/setcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
eos "github.com/eoscanada/eos-go"
)

func NewSetCodeTx(account eos.AccountName, wasmPath, abiPath string) (out *eos.Transaction, err error) {
func NewSetContract(account eos.AccountName, wasmPath, abiPath string) (out []*eos.Action, err error) {
codeContent, err := ioutil.ReadFile(wasmPath)
if err != nil {
return nil, err
Expand Down Expand Up @@ -55,6 +55,66 @@ func NewSetCodeTx(account eos.AccountName, wasmPath, abiPath string) (out *eos.T
}),
},
}
return actions, nil
}

func NewSetCode(account eos.AccountName, wasmPath string) (out *eos.Action, err error) {
codeContent, err := ioutil.ReadFile(wasmPath)
if err != nil {
return nil, err
}

return &eos.Action{
Account: AN("eosio"),
Name: ActN("setcode"),
Authorization: []eos.PermissionLevel{
{account, eos.PermissionName("active")},
},
ActionData: eos.NewActionData(SetCode{
Account: account,
VMType: 0,
VMVersion: 0,
Code: eos.HexBytes(codeContent),
}),
}, nil
}

func NewSetABI(account eos.AccountName, abiPath string) (out *eos.Action, err error) {
abiContent, err := ioutil.ReadFile(abiPath)
if err != nil {
return nil, err
}

var abiDef eos.ABI
if err := json.Unmarshal(abiContent, &abiDef); err != nil {
return nil, fmt.Errorf("unmarshal ABI file: %s", err)
}

abiPacked, err := eos.MarshalBinary(abiDef)
if err != nil {
return nil, fmt.Errorf("packing ABI: %s", err)
}

return &eos.Action{
Account: AN("eosio"),
Name: ActN("setabi"),
Authorization: []eos.PermissionLevel{
{account, eos.PermissionName("active")},
},
ActionData: eos.NewActionData(SetABI{
Account: account,
ABI: eos.HexBytes(abiPacked),
}),
}, nil
}

// NewSetCodeTx is _deprecated_. Use NewSetContract instead, and build
// your transaction yourself.
func NewSetCodeTx(account eos.AccountName, wasmPath, abiPath string) (out *eos.Transaction, err error) {
actions, err := NewSetContract(account, wasmPath, abiPath)
if err != nil {
return nil, err
}
return &eos.Transaction{Actions: actions}, nil
}

Expand Down
24 changes: 24 additions & 0 deletions system/setramrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package system

import (
eos "github.com/eoscanada/eos-go"
)

func NewSetRAMRate(bytesPerBlock uint16) *eos.Action {
a := &eos.Action{
Account: AN("eosio"),
Name: ActN("setram"),
Authorization: []eos.PermissionLevel{
{AN("eosio"), eos.PermissionName("active")},
},
ActionData: eos.NewActionData(SetRAMRate{
BytesPerBlock: bytesPerBlock,
}),
}
return a
}

// SetRAMRate represents the system contract's `setramrate` action.
type SetRAMRate struct {
BytesPerBlock uint16 `json:"bytes_per_block"`
}

0 comments on commit ec64637

Please sign in to comment.