Skip to content

Commit

Permalink
Merge pull request #241 from stellar/add-contract-code-fee-structure
Browse files Browse the repository at this point in the history
Add contract code fees
  • Loading branch information
chowbao authored Apr 30, 2024
2 parents d39b487 + a3aa552 commit 834b7bb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
35 changes: 35 additions & 0 deletions internal/transform/contract_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ func TransformContractCode(ledgerChange ingest.Change, header xdr.LedgerHeaderHi

ledgerSequence := header.Header.LedgerSeq

var outputNInstructions uint32
var outputNFunctions uint32
var outputNGlobals uint32
var outputNTableEntries uint32
var outputNTypes uint32
var outputNDataSegments uint32
var outputNElemSegments uint32
var outputNImports uint32
var outputNExports uint32
var outputNDataSegmentBytes uint32

extV1, ok := contractCode.Ext.GetV1()
if ok {
outputNInstructions = uint32(extV1.CostInputs.NInstructions)
outputNFunctions = uint32(extV1.CostInputs.NFunctions)
outputNGlobals = uint32(extV1.CostInputs.NGlobals)
outputNTableEntries = uint32(extV1.CostInputs.NTableEntries)
outputNTypes = uint32(extV1.CostInputs.NTypes)
outputNDataSegments = uint32(extV1.CostInputs.NDataSegments)
outputNElemSegments = uint32(extV1.CostInputs.NElemSegments)
outputNImports = uint32(extV1.CostInputs.NImports)
outputNExports = uint32(extV1.CostInputs.NExports)
outputNDataSegmentBytes = uint32(extV1.CostInputs.NDataSegmentBytes)
}

transformedCode := ContractCodeOutput{
ContractCodeHash: contractCodeHash,
ContractCodeExtV: int32(contractCodeExtV),
Expand All @@ -47,6 +72,16 @@ func TransformContractCode(ledgerChange ingest.Change, header xdr.LedgerHeaderHi
ClosedAt: closedAt,
LedgerSequence: uint32(ledgerSequence),
LedgerKeyHash: ledgerKeyHash,
NInstructions: outputNInstructions,
NFunctions: outputNFunctions,
NGlobals: outputNGlobals,
NTableEntries: outputNTableEntries,
NTypes: outputNTypes,
NDataSegments: outputNDataSegments,
NElemSegments: outputNElemSegments,
NImports: outputNImports,
NExports: outputNExports,
NDataSegmentBytes: outputNDataSegmentBytes,
}
return transformedCode, nil
}
24 changes: 24 additions & 0 deletions internal/transform/contract_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ func makeContractCodeTestInput() []ingest.Change {
Hash: hash,
Ext: xdr.ContractCodeEntryExt{
V: 1,
V1: &xdr.ContractCodeEntryV1{
CostInputs: xdr.ContractCodeCostInputs{
NInstructions: 1,
NFunctions: 2,
NGlobals: 3,
NTableEntries: 4,
NTypes: 5,
NDataSegments: 6,
NElemSegments: 7,
NImports: 8,
NExports: 9,
NDataSegmentBytes: 10,
},
},
},
},
},
Expand All @@ -94,6 +108,16 @@ func makeContractCodeTestOutput() []ContractCodeOutput {
LedgerSequence: 10,
ClosedAt: time.Date(1970, time.January, 1, 0, 16, 40, 0, time.UTC),
LedgerKeyHash: "dfed061dbe464e0ff320744fcd604ac08b39daa74fa24110936654cbcb915ccc",
NInstructions: 1,
NFunctions: 2,
NGlobals: 3,
NTableEntries: 4,
NTypes: 5,
NDataSegments: 6,
NElemSegments: 7,
NImports: 8,
NExports: 9,
NDataSegmentBytes: 10,
},
}
}
10 changes: 10 additions & 0 deletions internal/transform/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ type ContractCodeOutput struct {
LedgerSequence uint32 `json:"ledger_sequence"`
LedgerKeyHash string `json:"ledger_key_hash"`
//ContractCodeCode string `json:"contract_code"`
NInstructions uint32 `json:"n_instructions"`
NFunctions uint32 `json:"n_functions"`
NGlobals uint32 `json:"n_globals"`
NTableEntries uint32 `json:"n_table_entries"`
NTypes uint32 `json:"n_types"`
NDataSegments uint32 `json:"n_data_segments"`
NElemSegments uint32 `json:"n_elem_segments"`
NImports uint32 `json:"n_imports"`
NExports uint32 `json:"n_exports"`
NDataSegmentBytes uint32 `json:"n_data_segment_bytes"`
}

// ConfigSettingOutput is a representation of soroban config settings that aligns with the Bigquery table config_settings
Expand Down

0 comments on commit 834b7bb

Please sign in to comment.