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
billettc committed Jan 8, 2019
2 parents 299c816 + 25bc9ae commit f969a20
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ func (api *API) GetTableRows(params GetTableRowsRequest) (out *GetTableRowsResp,
return
}

func (api *API) GetRawABI(params GetRawABIRequest) (out *GetRawABIResp, err error) {
err = api.call("chain", "get_raw_abi", params, &out)
return
}

func (api *API) GetRequiredKeys(tx *Transaction) (out *GetRequiredKeysResp, err error) {
keys, err := api.Signer.AvailableKeys()
if err != nil {
Expand All @@ -532,6 +537,16 @@ func (api *API) GetCurrencyBalance(account AccountName, symbol string, code Acco
return
}

func (api *API) GetCurrencyStats(code AccountName, symbol string) (out *GetCurrencyStatsResp, err error) {
params := M{"code": code, "symbol": symbol}

outWrapper := make(map[string]*GetCurrencyStatsResp)
err = api.call("chain", "get_currency_stats", params, &outWrapper)
out = outWrapper[symbol]

return
}

// See more here: libraries/chain/contracts/abi_serializer.cpp:58...

func (api *API) call(baseAPI string, endpoint string, body interface{}, out interface{}) error {
Expand Down
18 changes: 18 additions & 0 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ type Currency struct {
Name CurrencyName
}

type GetRawABIRequest struct {
AccountName string `json:"account_name"`
ABIHash Checksum256 `json:"abi_hash,omitempty"`
}

type GetRawABIResp struct {
AccountName string `json:"account_name"`
CodeHash Checksum256 `json:"code_hash"`
ABIHash Checksum256 `json:"abi_hash"`
ABI Blob `json:"abi"`
}

type GetRequiredKeysResp struct {
RequiredKeys []ecc.PublicKey `json:"required_keys"`
}
Expand Down Expand Up @@ -400,3 +412,9 @@ type ActionsResp struct {
Actions []ActionResp `json:"actions"`
LastIrreversibleBlock uint32 `json:"last_irreversible_block"`
}

type GetCurrencyStatsResp struct {
Supply Asset `json:"supply"`
MaxSupply Asset `json:"max_supply"`
Issuer AccountName `json:"issuer"`
}
17 changes: 17 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eos

import (
"encoding/base64"
"encoding/binary"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -797,3 +798,19 @@ func (i *Uint128) UnmarshalJSON(data []byte) error {

return nil
}

// Blob

// Blob is base64 encoded data
// https://github.com/EOSIO/fc/blob/0e74738e938c2fe0f36c5238dbc549665ddaef82/include/fc/variant.hpp#L47
type Blob string

// Data returns decoded base64 data
func (b Blob) Data() ([]byte, error) {
return base64.StdEncoding.DecodeString(string(b))
}

// String returns the blob as a string
func (b Blob) String() string {
return string(b)
}
21 changes: 21 additions & 0 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,24 @@ func EqualNoDiff(t *testing.T, expected interface{}, actual interface{}, message

return true
}

func TestBlob(t *testing.T) {
b := Blob("RU9TIEdv")

t.Run("String", func(tt *testing.T) {
assert.Equal(tt, "RU9TIEdv", b.String())
})

t.Run("Data", func(tt *testing.T) {
data, err := b.Data()
require.Nil(tt, err)
assert.Equal(tt, []byte("EOS Go"), data)
})

t.Run("malformed data", func(tt *testing.T) {
b := Blob("not base64")
data, err := b.Data()
require.Equal(tt, "illegal base64 data at input byte 3", err.Error())
assert.Empty(tt, data)
})
}

0 comments on commit f969a20

Please sign in to comment.