Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use our types for pool/bech32 #645

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ toolchain go1.21.5
require (
filippo.io/edwards25519 v1.1.0
github.com/blinklabs-io/ouroboros-mock v0.3.1
github.com/cosmos/cosmos-sdk v0.50.6
github.com/fxamacker/cbor/v2 v2.6.0
github.com/jinzhu/copier v0.4.0
github.com/utxorpc/go-codegen v0.5.1
Expand All @@ -16,7 +15,10 @@ require (
)

require (
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/sys v0.20.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/blinklabs-io/ouroboros-mock v0.3.1 h1:oQiMgH0VgsJIGy4lJGaySegObq5FsVgFTYXUO2PS2T8=
github.com/blinklabs-io/ouroboros-mock v0.3.1/go.mod h1:6DosKZuBZ4mmvky3hXUzGZqqb/KhbwOiKOldwAtNoxc=
github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cosmos/cosmos-sdk v0.50.6 h1:efR3MsvMHX5sxS3be+hOobGk87IzlZbSpsI2x/Vw3hk=
github.com/cosmos/cosmos-sdk v0.50.6/go.mod h1:lVkRY6cdMJ0fG3gp8y4hFrsKZqF4z7y0M2UXFb9Yt40=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fxamacker/cbor/v2 v2.6.0 h1:sU6J2usfADwWlYDAFhZBQ6TnLFBHxgesMrQfQgk1tWA=
Expand Down
29 changes: 4 additions & 25 deletions ledger/verify_block_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"strconv"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/cosmos/cosmos-sdk/types/bech32"
"golang.org/x/crypto/blake2b"
)

Expand Down Expand Up @@ -244,16 +243,11 @@ func GetBlockOutput(
// We will only focus on:
// pool_registration = (3, pool_params)
// pool_retirement = (4, pool_keyhash, epoch)
for certIndex, cert := range tx.Certificates() {
for _, cert := range tx.Certificates() {
switch v := cert.(type) {
case *PoolRegistrationCertificate:
poolIdBytes := v.Operator[:]
vrfKeyHashBytes := v.VrfKeyHash[:]
vrfKeyHashHex := hex.EncodeToString(vrfKeyHashBytes)
poolId, poolIdError := PoolIdToBech32(poolIdBytes)
if poolIdError != nil {
return nil, nil, nil, fmt.Errorf("GetBlockOutput: RegisSPO => PoolIdToBech32 , tx index %v, cert index %v, error, %v", txIndex, certIndex, poolIdError.Error())
}
poolId := NewBlake2b224(v.Operator[:]).String()
vrfKeyHashHex := hex.EncodeToString(v.VrfKeyHash[:])
regisCerts = append(regisCerts, RegisCert{
RegisPoolId: poolId,
RegisPoolVrf: vrfKeyHashHex,
Expand All @@ -262,11 +256,7 @@ func GetBlockOutput(

case *PoolRetirementCertificate:
// pool_retirement
poolIdBytes := v.PoolKeyHash[:]
poolId, poolIdError := PoolIdToBech32(poolIdBytes)
if poolIdError != nil {
return nil, nil, nil, fmt.Errorf("GetBlockOutput: RetireSPO => PoolIdToBech32, tx index %v, cert index %v, error, %v", txIndex, certIndex, poolIdError.Error())
}
poolId := NewBlake2b224(v.PoolKeyHash[:]).String()
retireEpoch := v.Epoch
deRegisCerts = append(deRegisCerts, DeRegisCert{
DeRegisPoolId: poolId,
Expand All @@ -281,17 +271,6 @@ func GetBlockOutput(
return outputs, regisCerts, deRegisCerts, nil
}

func PoolIdToBech32(data []byte) (string, error) {
pool, err := bech32.ConvertAndEncode("pool", data)
if err != nil {
return "", fmt.Errorf(
"PoolIdToBech32: ConvertAndEncode error, %v",
err.Error(),
)
}
return pool, nil
}

func ExtractTokens(output TransactionOutput) ([]UTXOOutputToken, error) {
var outputTokens []UTXOOutputToken
// append lovelace first
Expand Down