Skip to content

Commit

Permalink
refactor: use our types for pool/bech32
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 committed May 27, 2024
1 parent 3baed02 commit baa3621
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 31 deletions.
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

0 comments on commit baa3621

Please sign in to comment.