diff --git a/internal/ship/contract_row.go b/internal/ship/contract_row.go new file mode 100644 index 0000000..a5b785f --- /dev/null +++ b/internal/ship/contract_row.go @@ -0,0 +1,21 @@ +package ship + +import ( + "github.com/mitchellh/mapstructure" + "github.com/shufflingpixels/antelope-go/chain" +) + +type ContractRow struct { + Code chain.Name `mapstructure:"code"` + Scope chain.Name `mapstructure:"scope"` + Table chain.Name `mapstructure:"table"` + PrimaryKey string `mapstructure:"primary_key"` + Payer chain.Name `mapstructure:"payer"` + Value chain.Bytes `mapstructure:"value"` +} + +func DecodeContractRow(v map[string]interface{}) (*ContractRow, error) { + out := &ContractRow{} + err := mapstructure.WeakDecode(v, out) + return out, err +} diff --git a/internal/ship/contract_row_test.go b/internal/ship/contract_row_test.go new file mode 100644 index 0000000..6a46be6 --- /dev/null +++ b/internal/ship/contract_row_test.go @@ -0,0 +1,32 @@ +package ship_test + +import ( + "testing" + + "github.com/eosswedenorg/thalos/internal/ship" + "github.com/shufflingpixels/antelope-go/chain" + "github.com/stretchr/testify/assert" +) + +func TestContractRow_Decode(t *testing.T) { + expected := &ship.ContractRow{ + Code: chain.N("eosio"), + Scope: chain.N("scope"), + Table: chain.N("accounts"), + PrimaryKey: "1278127812", + Payer: chain.N("account1"), + Value: []byte{0x01, 0x01, 0x02, 0x03}, + } + + actual, err := ship.DecodeContractRow(map[string]any{ + "code": uint64(6138663577826885632), + "scope": uint64(13990807175891517440), + "table": uint64(3607749779137757184), + "primary_key": uint32(1278127812), + "payer": uint64(3607749778751881216), + "value": []byte{0x01, 0x01, 0x02, 0x03}, + }) + + assert.NoError(t, err) + assert.Equal(t, expected, actual) +}