diff --git a/api.go b/api.go index ec456e13..da98a011 100644 --- a/api.go +++ b/api.go @@ -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 { diff --git a/responses.go b/responses.go index 43239075..f5909b1e 100644 --- a/responses.go +++ b/responses.go @@ -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"` } diff --git a/types.go b/types.go index 30025f2b..2a8a87f9 100644 --- a/types.go +++ b/types.go @@ -1,6 +1,7 @@ package eos import ( + "encoding/base64" "encoding/binary" "encoding/hex" "encoding/json" @@ -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) +} diff --git a/types_test.go b/types_test.go index b2a61194..b1b8c331 100644 --- a/types_test.go +++ b/types_test.go @@ -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) + }) +}