mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-17 04:30:03 +02:00
adding internal/ship/contract_row.go
This commit is contained in:
parent
3d83fcc869
commit
0e75fb869b
2 changed files with 53 additions and 0 deletions
21
internal/ship/contract_row.go
Normal file
21
internal/ship/contract_row.go
Normal file
|
|
@ -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
|
||||
}
|
||||
32
internal/ship/contract_row_test.go
Normal file
32
internal/ship/contract_row_test.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue