mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-18 04:40:03 +02:00
api/message/types.go: Adding Blocknum and Timestamp to ActionTrace struct
This commit is contained in:
parent
e2b19b7404
commit
ae6f3f11a9
3 changed files with 596 additions and 80 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/eosswedenorg/thalos/api/message"
|
||||
"github.com/shamaton/msgpack/v2"
|
||||
|
|
@ -30,12 +31,14 @@ func TestMsgpack_EncodeActionTrace(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
msg := message.ActionTrace{
|
||||
TxID: "edc06dce6320459fd644756972048da453b2816b0a434c37ddffde36778dcab3",
|
||||
Name: "sellitem",
|
||||
Contract: "mygame",
|
||||
Receiver: "eosio",
|
||||
Data: dataJson,
|
||||
HexData: "d0fa1b2ab8a6fd0d1b0173df91aa9ffd277642d05780cf750",
|
||||
TxID: "edc06dce6320459fd644756972048da453b2816b0a434c37ddffde36778dcab3",
|
||||
BlockNum: 12345,
|
||||
Timestamp: time.Unix(1699617279, int64(time.Millisecond)*500),
|
||||
Name: "sellitem",
|
||||
Contract: "mygame",
|
||||
Receiver: "eosio",
|
||||
Data: dataJson,
|
||||
HexData: "d0fa1b2ab8a6fd0d1b0173df91aa9ffd277642d05780cf750",
|
||||
Authorization: []message.PermissionLevel{
|
||||
{Actor: "mygame", Permission: "active"},
|
||||
},
|
||||
|
|
@ -48,7 +51,7 @@ func TestMsgpack_EncodeActionTrace(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
expected := []byte{
|
||||
0x8a, 0xa5, 0x74, 0x78, 0x5f, 0x69, 0x64, 0xd9,
|
||||
0x8c, 0xa5, 0x74, 0x78, 0x5f, 0x69, 0x64, 0xd9,
|
||||
0x40, 0x65, 0x64, 0x63, 0x30, 0x36, 0x64, 0x63,
|
||||
0x65, 0x36, 0x33, 0x32, 0x30, 0x34, 0x35, 0x39,
|
||||
0x66, 0x64, 0x36, 0x34, 0x34, 0x37, 0x35, 0x36,
|
||||
|
|
@ -57,50 +60,55 @@ func TestMsgpack_EncodeActionTrace(t *testing.T) {
|
|||
0x62, 0x30, 0x61, 0x34, 0x33, 0x34, 0x63, 0x33,
|
||||
0x37, 0x64, 0x64, 0x66, 0x66, 0x64, 0x65, 0x33,
|
||||
0x36, 0x37, 0x37, 0x38, 0x64, 0x63, 0x61, 0x62,
|
||||
0x33, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa8, 0x73,
|
||||
0x65, 0x6c, 0x6c, 0x69, 0x74, 0x65, 0x6d, 0xa8,
|
||||
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74,
|
||||
0xa6, 0x6d, 0x79, 0x67, 0x61, 0x6d, 0x65, 0xa8,
|
||||
0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x72,
|
||||
0xa5, 0x65, 0x6f, 0x73, 0x69, 0x6f, 0xa4, 0x64,
|
||||
0x61, 0x74, 0x61, 0xc4, 0x9b, 0x7b, 0x22, 0x61,
|
||||
0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x3a, 0x22,
|
||||
0x31, 0x30, 0x30, 0x30, 0x2e, 0x30, 0x30, 0x30,
|
||||
0x30, 0x20, 0x53, 0x43, 0x41, 0x4d, 0x22, 0x2c,
|
||||
0x22, 0x66, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x22,
|
||||
0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x31,
|
||||
0x22, 0x2c, 0x22, 0x69, 0x74, 0x65, 0x6d, 0x22,
|
||||
0x3a, 0x7b, 0x22, 0x61, 0x67, 0x69, 0x22, 0x3a,
|
||||
0x22, 0x32, 0x30, 0x22, 0x2c, 0x22, 0x64, 0x75,
|
||||
0x72, 0x22, 0x3a, 0x22, 0x31, 0x30, 0x30, 0x22,
|
||||
0x2c, 0x22, 0x69, 0x64, 0x22, 0x3a, 0x22, 0x32,
|
||||
0x31, 0x33, 0x31, 0x32, 0x34, 0x32, 0x22, 0x2c,
|
||||
0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22,
|
||||
0x47, 0x72, 0x65, 0x61, 0x74, 0x20, 0x53, 0x77,
|
||||
0x6f, 0x72, 0x64, 0x22, 0x2c, 0x22, 0x71, 0x75,
|
||||
0x61, 0x6c, 0x22, 0x3a, 0x22, 0x65, 0x70, 0x69,
|
||||
0x63, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x22,
|
||||
0x3a, 0x22, 0x31, 0x30, 0x30, 0x22, 0x7d, 0x2c,
|
||||
0x22, 0x74, 0x6f, 0x22, 0x3a, 0x22, 0x61, 0x63,
|
||||
0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0x22, 0x7d,
|
||||
0xa8, 0x68, 0x65, 0x78, 0x5f, 0x64, 0x61, 0x74,
|
||||
0x61, 0xd9, 0x31, 0x64, 0x30, 0x66, 0x61, 0x31,
|
||||
0x62, 0x32, 0x61, 0x62, 0x38, 0x61, 0x36, 0x66,
|
||||
0x64, 0x30, 0x64, 0x31, 0x62, 0x30, 0x31, 0x37,
|
||||
0x33, 0x64, 0x66, 0x39, 0x31, 0x61, 0x61, 0x39,
|
||||
0x66, 0x66, 0x64, 0x32, 0x37, 0x37, 0x36, 0x34,
|
||||
0x32, 0x64, 0x30, 0x35, 0x37, 0x38, 0x30, 0x63,
|
||||
0x66, 0x37, 0x35, 0x30, 0xad, 0x61, 0x75, 0x74,
|
||||
0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x91, 0x82, 0xa5, 0x61, 0x63, 0x74,
|
||||
0x6f, 0x72, 0xa6, 0x6d, 0x79, 0x67, 0x61, 0x6d,
|
||||
0x65, 0xaa, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x73,
|
||||
0x73, 0x69, 0x6f, 0x6e, 0xa6, 0x61, 0x63, 0x74,
|
||||
0x69, 0x76, 0x65, 0xa6, 0x65, 0x78, 0x63, 0x65,
|
||||
0x70, 0x74, 0xa6, 0x65, 0x72, 0x72, 0x73, 0x74,
|
||||
0x72, 0xa5, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x02,
|
||||
0xa6, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0xc4,
|
||||
0x4, 0xde, 0xad, 0xbe, 0xef,
|
||||
0x33, 0xa8, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x6e,
|
||||
0x75, 0x6d, 0xcd, 0x30, 0x39, 0xae, 0x62, 0x6c,
|
||||
0x6f, 0x63, 0x6b, 0x74, 0x69, 0x6d, 0x65, 0x73,
|
||||
0x74, 0x61, 0x6d, 0x70, 0xd7, 0xff, 0x77, 0x35,
|
||||
0x94, 0x00, 0x65, 0x4e, 0x19, 0xff, 0xa4, 0x6e,
|
||||
0x61, 0x6d, 0x65, 0xa8, 0x73, 0x65, 0x6c, 0x6c,
|
||||
0x69, 0x74, 0x65, 0x6d, 0xa8, 0x63, 0x6f, 0x6e,
|
||||
0x74, 0x72, 0x61, 0x63, 0x74, 0xa6, 0x6d, 0x79,
|
||||
0x67, 0x61, 0x6d, 0x65, 0xa8, 0x72, 0x65, 0x63,
|
||||
0x65, 0x69, 0x76, 0x65, 0x72, 0xa5, 0x65, 0x6f,
|
||||
0x73, 0x69, 0x6f, 0xa4, 0x64, 0x61, 0x74, 0x61,
|
||||
0xc4, 0x9b, 0x7b, 0x22, 0x61, 0x6d, 0x6f, 0x75,
|
||||
0x6e, 0x74, 0x22, 0x3a, 0x22, 0x31, 0x30, 0x30,
|
||||
0x30, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x20, 0x53,
|
||||
0x43, 0x41, 0x4d, 0x22, 0x2c, 0x22, 0x66, 0x72,
|
||||
0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x61, 0x63, 0x63,
|
||||
0x6f, 0x75, 0x6e, 0x74, 0x31, 0x22, 0x2c, 0x22,
|
||||
0x69, 0x74, 0x65, 0x6d, 0x22, 0x3a, 0x7b, 0x22,
|
||||
0x61, 0x67, 0x69, 0x22, 0x3a, 0x22, 0x32, 0x30,
|
||||
0x22, 0x2c, 0x22, 0x64, 0x75, 0x72, 0x22, 0x3a,
|
||||
0x22, 0x31, 0x30, 0x30, 0x22, 0x2c, 0x22, 0x69,
|
||||
0x64, 0x22, 0x3a, 0x22, 0x32, 0x31, 0x33, 0x31,
|
||||
0x32, 0x34, 0x32, 0x22, 0x2c, 0x22, 0x6e, 0x61,
|
||||
0x6d, 0x65, 0x22, 0x3a, 0x22, 0x47, 0x72, 0x65,
|
||||
0x61, 0x74, 0x20, 0x53, 0x77, 0x6f, 0x72, 0x64,
|
||||
0x22, 0x2c, 0x22, 0x71, 0x75, 0x61, 0x6c, 0x22,
|
||||
0x3a, 0x22, 0x65, 0x70, 0x69, 0x63, 0x22, 0x2c,
|
||||
0x22, 0x73, 0x74, 0x72, 0x22, 0x3a, 0x22, 0x31,
|
||||
0x30, 0x30, 0x22, 0x7d, 0x2c, 0x22, 0x74, 0x6f,
|
||||
0x22, 0x3a, 0x22, 0x61, 0x63, 0x63, 0x6f, 0x75,
|
||||
0x6e, 0x74, 0x32, 0x22, 0x7d, 0xa8, 0x68, 0x65,
|
||||
0x78, 0x5f, 0x64, 0x61, 0x74, 0x61, 0xd9, 0x31,
|
||||
0x64, 0x30, 0x66, 0x61, 0x31, 0x62, 0x32, 0x61,
|
||||
0x62, 0x38, 0x61, 0x36, 0x66, 0x64, 0x30, 0x64,
|
||||
0x31, 0x62, 0x30, 0x31, 0x37, 0x33, 0x64, 0x66,
|
||||
0x39, 0x31, 0x61, 0x61, 0x39, 0x66, 0x66, 0x64,
|
||||
0x32, 0x37, 0x37, 0x36, 0x34, 0x32, 0x64, 0x30,
|
||||
0x35, 0x37, 0x38, 0x30, 0x63, 0x66, 0x37, 0x35,
|
||||
0x30, 0xad, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72,
|
||||
0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x91,
|
||||
0x82, 0xa5, 0x61, 0x63, 0x74, 0x6f, 0x72, 0xa6,
|
||||
0x6d, 0x79, 0x67, 0x61, 0x6d, 0x65, 0xaa, 0x70,
|
||||
0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0xa6, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65,
|
||||
0xa6, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0xa6,
|
||||
0x65, 0x72, 0x72, 0x73, 0x74, 0x72, 0xa5, 0x65,
|
||||
0x72, 0x72, 0x6f, 0x72, 0x02, 0xa6, 0x72, 0x65,
|
||||
0x74, 0x75, 0x72, 0x6e, 0xc4, 0x04, 0xde, 0xad,
|
||||
0xbe, 0xef,
|
||||
}
|
||||
|
||||
assert.Equal(t, expected, data)
|
||||
|
|
@ -109,7 +117,7 @@ func TestMsgpack_EncodeActionTrace(t *testing.T) {
|
|||
func TestMsgpack_Decode(t *testing.T) {
|
||||
RegisterGeneratedResolver()
|
||||
|
||||
data := []byte("\x8a\xa5tx_id\xd9@edc06dce6320459fd644756972048da453b2816b0a434c37ddffde36778dcab3\xa4name\xa4drop\xa8contract\xa6mygame\xa8receiver\xa8account1\xa4dataċ{\"dropped_from_id\":674562,\"item\":{\"dur\":145,\"id\":49623,\"name\":\"Shadowmourne\",\"qual\":\"legendary\",\"sta\":198,\"str\":223},\"receiver\":\"account1\"}\xa8hex_data\xda\x01\x167b2264726f707065645f66726f6d5f6964223a3637343536322c226974656d223a7b22647572223a3134352c226964223a34393632332c226e616d65223a22536861646f776d6f75726e65222c227175616c223a226c6567656e64617279222c22737461223a3139382c22737472223a3232337d2c227265636569766572223a226163636f756e7431227d\xadauthorization\x91\x82\xa5actor\xa6mygame\xaapermission\xa6active\xa6except\xa6errstr\xa5error\x02\xa6return\xc4\x04ޭ\xbe\xef")
|
||||
data := []byte("\x8c\xa5tx_id\xd9@edc06dce6320459fd644756972048da453b2816b0a434c37ddffde36778dcab3\xa8blocknum\xce\x00\x85F7\xaeblocktimestamp\xd6\xffH\xf1U\x1f\xa4name\xa4drop\xa8contract\xa6mygame\xa8receiver\xa8account1\xa4dataċ{\"dropped_from_id\":674562,\"item\":{\"dur\":145,\"id\":49623,\"name\":\"Shadowmourne\",\"qual\":\"legendary\",\"sta\":198,\"str\":223},\"receiver\":\"account1\"}\xa8hex_data\xda\x01\x167b2264726f707065645f66726f6d5f6964223a3637343536322c226974656d223a7b22647572223a3134352c226964223a34393632332c226e616d65223a22536861646f776d6f75726e65222c227175616c223a226c6567656e64617279222c22737461223a3139382c22737472223a3232337d2c227265636569766572223a226163636f756e7431227d\xadauthorization\x91\x82\xa5actor\xa6mygame\xaapermission\xa6active\xa6except\xa6errstr\xa5error\x02\xa6return\xc4\x04ޭ\xbe\xef")
|
||||
|
||||
dataJson, err := json.Marshal(map[string]interface{}{
|
||||
"item": map[string]interface{}{
|
||||
|
|
@ -127,12 +135,14 @@ func TestMsgpack_Decode(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
expected := message.ActionTrace{
|
||||
TxID: "edc06dce6320459fd644756972048da453b2816b0a434c37ddffde36778dcab3",
|
||||
Name: "drop",
|
||||
Contract: "mygame",
|
||||
Receiver: "account1",
|
||||
Data: dataJson,
|
||||
HexData: hex.EncodeToString(dataJson),
|
||||
TxID: "edc06dce6320459fd644756972048da453b2816b0a434c37ddffde36778dcab3",
|
||||
BlockNum: 8734263,
|
||||
Timestamp: time.Unix(1223775519, 0),
|
||||
Name: "drop",
|
||||
Contract: "mygame",
|
||||
Receiver: "account1",
|
||||
Data: dataJson,
|
||||
HexData: hex.EncodeToString(dataJson),
|
||||
Authorization: []message.PermissionLevel{
|
||||
{Actor: "mygame", Permission: "active"},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue