From 9ed9d7d72161e77caff324d60cc17dfad53c4a7a Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Tue, 21 Jul 2020 00:53:54 -0400 Subject: [PATCH] All sections supported! --- decoder.go | 5 +++++ snapshot/snapshot_test.go | 27 ++++++++++++++------------- snapshot/typesv3.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/decoder.go b/decoder.go index 75c06ce8..baaee068 100644 --- a/decoder.go +++ b/decoder.go @@ -369,6 +369,11 @@ func (d *Decoder) Decode(v interface{}, options ...DecodeOption) (err error) { tp, err = d.ReadTimePoint() rv.Set(reflect.ValueOf(tp)) return + case *TimePointSec: + var tp TimePointSec + tp, err = d.ReadTimePointSec() + rv.Set(reflect.ValueOf(tp)) + return case *BlockTimestamp: var bt BlockTimestamp bt, err = d.ReadBlockTimestamp() diff --git a/snapshot/snapshot_test.go b/snapshot/snapshot_test.go index 63854593..70b97d87 100644 --- a/snapshot/snapshot_test.go +++ b/snapshot/snapshot_test.go @@ -47,18 +47,6 @@ func TestSnapshotRead(t *testing.T) { switch section.Name { case "eosio::chain::chain_snapshot_header": require.NoError(t, readChainSnapshotHeader(section)) - case "eosio::chain::genesis_state": - // // THIS SEEMS TO EXIST ONLY IN VERSION 2 OF THE SNAPSHOT FILE FORMAT. - // // FOR NOW, WE ARE CONCENTRATING ON VERSION 3 (latest) - // cnt := make([]byte, section.BufferSize) - // _, err := section.Buffer.Read(cnt) - // require.NoError(t, err) - - // var state GenesisState - // assert.NoError(t, eos.UnmarshalBinary(cnt, &state)) - // cnt, _ = json.MarshalIndent(state, " ", " ") - // fmt.Println(string(cnt)) - case "eosio::chain::block_state": // require.NoError(t, readBlockState(section)) case "eosio::chain::account_object": @@ -76,8 +64,9 @@ func TestSnapshotRead(t *testing.T) { case "eosio::chain::block_summary_object": //require.NoError(t, readBlockSummary(section)) case "eosio::chain::transaction_object": + require.NoError(t, readTransactionObject(section)) case "eosio::chain::generated_transaction_object": - require.NoError(t, readGeneratedTransactionObject(section)) + // require.NoError(t, readGeneratedTransactionObject(section)) case "eosio::chain::code_object": // require.NoError(t, readCodeObject(section)) case "contract_tables": @@ -94,6 +83,18 @@ func TestSnapshotRead(t *testing.T) { // require.NoError(t, readResourceLimitsStateObject(section)) case "eosio::chain::resource_limits::resource_limits_config_object": // require.NoError(t, readResourceLimitsConfigObject(section)) + case "eosio::chain::genesis_state": + // // THIS SEEMS TO EXIST ONLY IN VERSION 2 OF THE SNAPSHOT FILE FORMAT. + // // FOR NOW, WE ARE CONCENTRATING ON VERSION 3 (latest) + // cnt := make([]byte, section.BufferSize) + // _, err := section.Buffer.Read(cnt) + // require.NoError(t, err) + + // var state GenesisState + // assert.NoError(t, eos.UnmarshalBinary(cnt, &state)) + // cnt, _ = json.MarshalIndent(state, " ", " ") + // fmt.Println(string(cnt)) + default: panic("unsupported section: " + section.Name) } diff --git a/snapshot/typesv3.go b/snapshot/typesv3.go index a058f2d0..4db95b31 100644 --- a/snapshot/typesv3.go +++ b/snapshot/typesv3.go @@ -863,3 +863,37 @@ func readGeneratedTransactionObject(section *Section) error { return nil } + +//// + +type TransactionObject struct { + Expiration eos.TimePointSec + TrxID eos.Checksum256 //< trx_id shou +} + +func readTransactionObject(section *Section) error { + cnt := make([]byte, section.BufferSize) + readz, err := section.Buffer.Read(cnt) + if err != nil { + return err + } + if readz != len(cnt) { + return fmt.Errorf("failed reading the whole code object section: %d of %d", readz, len(cnt)) + } + + for pos := 0; pos < int(section.BufferSize); { + d := eos.NewDecoder(cnt[pos:]) + var to TransactionObject + err = d.Decode(&to) + if err != nil { + return err + } + + out, _ := json.MarshalIndent(to, "", " ") + fmt.Println(string(out)) + + pos += d.LastPos() + } + + return nil +}