Skip to content

Commit

Permalink
Merge pull request #102 from Jeiwan/get_raw_abi
Browse files Browse the repository at this point in the history
 Add support for 'chain/get_raw_abi' API endpoint
  • Loading branch information
billettc authored Jan 8, 2019
2 parents 5119b9e + b066e43 commit 25bc9ae
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
5 changes: 5 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 Down
12 changes: 12 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
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 25bc9ae

Please sign in to comment.