Skip to content

Commit

Permalink
Merge pull request #227 from stellar/fix-soroban-hashes
Browse files Browse the repository at this point in the history
Fix soroban hashes to hexstring
  • Loading branch information
chowbao authored Feb 22, 2024
2 parents e1e76d0 + dc9c83e commit 81ee29d
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 14 deletions.
4 changes: 1 addition & 3 deletions internal/transform/contract_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/stellar/go/ingest"
"github.com/stellar/go/strkey"
"github.com/stellar/go/xdr"
"github.com/stellar/stellar-etl/internal/utils"
)
Expand All @@ -30,8 +29,7 @@ func TransformContractCode(ledgerChange ingest.Change, header xdr.LedgerHeaderHi

contractCodeExtV := contractCode.Ext.V

contractCodeHashByte, _ := contractCode.Hash.MarshalBinary()
contractCodeHash, _ := strkey.Encode(strkey.VersionByteContract, contractCodeHashByte)
contractCodeHash := contractCode.Hash.HexString()

closedAt, err := utils.TimePointToUTCTimeStamp(header.Header.ScpValue.CloseTime)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/transform/contract_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ func makeContractCodeTestInput() []ingest.Change {
func makeContractCodeTestOutput() []ContractCodeOutput {
return []ContractCodeOutput{
{
ContractCodeHash: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
ContractCodeHash: "0000000000000000000000000000000000000000000000000000000000000000",
ContractCodeExtV: 1,
LastModifiedLedger: 24229503,
LedgerEntryChange: 1,
Deleted: false,
LedgerSequence: 10,
ClosedAt: time.Date(1970, time.January, 1, 0, 16, 40, 0, time.UTC),
LedgerKeyHash: "CDP62BQ5XZDE4D7TEB2E7TLAJLAIWOO2U5H2EQIQSNTFJS6LSFOMZRZJ",
LedgerKeyHash: "dfed061dbe464e0ff320744fcd604ac08b39daa74fa24110936654cbcb915ccc",
},
}
}
2 changes: 1 addition & 1 deletion internal/transform/contract_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func makeContractDataTestOutput() []ContractDataOutput {
Deleted: false,
LedgerSequence: 10,
ClosedAt: time.Date(1970, time.January, 1, 0, 16, 40, 0, time.UTC),
LedgerKeyHash: "CCV7YMZHECK2TX2MGEGP6GEQIAMSVCXON5VCHNVUMKEJCFGYA4UMUUCA",
LedgerKeyHash: "abfc33272095a9df4c310cff189040192a8aee6f6a23b6b462889114d80728ca",
},
}
}
3 changes: 1 addition & 2 deletions internal/transform/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,7 @@ func contractCodeFromContractData(ledgerKey xdr.LedgerKey) string {
return ""
}

contractCodeHashByte, _ := contractCode.Hash.MarshalBinary()
contractCodeHash, _ := strkey.Encode(strkey.VersionByteContract, contractCodeHashByte)
contractCodeHash := contractCode.Hash.HexString()
return contractCodeHash
}

Expand Down
4 changes: 1 addition & 3 deletions internal/transform/ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/stellar/go/ingest"
"github.com/stellar/go/strkey"
"github.com/stellar/go/xdr"
"github.com/stellar/stellar-etl/internal/utils"
)
Expand All @@ -26,8 +25,7 @@ func TransformTtl(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEntr
return TtlOutput{}, nil
}

keyHashByte, _ := ttl.KeyHash.MarshalBinary()
keyHash, _ := strkey.Encode(strkey.VersionByteContract, keyHashByte)
keyHash := ttl.KeyHash.HexString()
liveUntilLedgerSeq := ttl.LiveUntilLedgerSeq

closedAt, err := utils.TimePointToUTCTimeStamp(header.Header.ScpValue.CloseTime)
Expand Down
2 changes: 1 addition & 1 deletion internal/transform/ttl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func makeTtlTestInput() []ingest.Change {
func makeTtlTestOutput() []TtlOutput {
return []TtlOutput{
{
KeyHash: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
KeyHash: "0000000000000000000000000000000000000000000000000000000000000000",
LiveUntilLedgerSeq: 123,
LastModifiedLedger: 1,
LedgerEntryChange: 1,
Expand Down
3 changes: 1 addition & 2 deletions internal/utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/stellar/go/ingest/ledgerbackend"
"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
"github.com/stellar/go/strkey"
"github.com/stellar/go/support/storage"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
Expand Down Expand Up @@ -710,7 +709,7 @@ func LedgerEntryToLedgerKeyHash(ledgerEntry xdr.LedgerEntry) string {
ledgerKey, _ := ledgerEntry.LedgerKey()
ledgerKeyByte, _ := ledgerKey.MarshalBinary()
hashedLedgerKeyByte := hash.Hash(ledgerKeyByte)
ledgerKeyHash, _ := strkey.Encode(strkey.VersionByteContract, hashedLedgerKeyByte[:])
ledgerKeyHash := hex.EncodeToString(hashedLedgerKeyByte[:])

return ledgerKeyHash
}

0 comments on commit 81ee29d

Please sign in to comment.