Skip to content

Commit

Permalink
Just one left!
Browse files Browse the repository at this point in the history
  • Loading branch information
abourget committed Jul 21, 2020
1 parent 3250a49 commit 8bfe0e8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
6 changes: 4 additions & 2 deletions snapshot/snapshot_test.go
Expand Up @@ -77,7 +77,9 @@ func TestSnapshotRead(t *testing.T) {
//require.NoError(t, readBlockSummary(section))
case "eosio::chain::transaction_object":
case "eosio::chain::generated_transaction_object":
require.NoError(t, readGeneratedTransactionObject(section))
case "eosio::chain::code_object":
// require.NoError(t, readCodeObject(section))
case "contract_tables":
// require.NoError(t, readContractTables(section))
case "eosio::chain::permission_object":
Expand All @@ -89,9 +91,9 @@ func TestSnapshotRead(t *testing.T) {
case "eosio::chain::resource_limits::resource_usage_object":
// require.NoError(t, readResourceUsageObject(section))
case "eosio::chain::resource_limits::resource_limits_state_object":
require.NoError(t, readResourceLimitsStateObject(section))
// require.NoError(t, readResourceLimitsStateObject(section))
case "eosio::chain::resource_limits::resource_limits_config_object":
require.NoError(t, readResourceLimitsConfigObject(section))
// require.NoError(t, readResourceLimitsConfigObject(section))
default:
panic("unsupported section: " + section.Name)
}
Expand Down
78 changes: 78 additions & 0 deletions snapshot/typesv3.go
Expand Up @@ -785,3 +785,81 @@ func readResourceLimitsConfigObject(section *Section) error {

return nil
}

////

type CodeObject struct {
CodeHash eos.Checksum256 //< code_hash should not be changed within a chainbase modifier lambda
Code eos.HexBytes
CodeRefCount eos.Uint64
FirstBlockUsed uint32
VMType uint8 //< vm_type should not be changed within a chainbase modifier lambda
VMVersion uint8 //< vm_version should not be changed within a chainbase modifier lambda
}

func readCodeObject(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 co CodeObject
err = d.Decode(&co)
if err != nil {
return err
}

out, _ := json.MarshalIndent(co, "", " ")
fmt.Println(string(out))

pos += d.LastPos()
}

return nil
}

////

type GeneratedTransactionObject struct {
TrxID eos.Checksum256 //< trx_id should not be changed within a chainbase modifier lambda
Sender eos.AccountName //< sender should not be changed within a chainbase modifier lambda
SenderID eos.Uint128 /// ID given this transaction by the sender (should not be changed within a chainbase modifier lambda)
Payer eos.AccountName
DelayUntil eos.TimePoint /// this generated transaction will not be applied until the specified time
Expiration eos.TimePoint /// this generated transaction will not be applied after time
Published eos.TimePoint
PackedTrx eos.HexBytes
}

func readGeneratedTransactionObject(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 gto GeneratedTransactionObject
err = d.Decode(&gto)
if err != nil {
return err
}

out, _ := json.MarshalIndent(gto, "", " ")
fmt.Println(string(out))

pos += d.LastPos()
}

return nil
}

0 comments on commit 8bfe0e8

Please sign in to comment.