Skip to content

Commit 0f9eabb

Browse files
author
Jenita
committed
feat: created genesis pools from shelly genesis
Signed-off-by: Jenita <[email protected]>
1 parent c44fbd3 commit 0f9eabb

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

ledger/shelley/genesis.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"encoding/hex"
1919
"encoding/json"
2020
"errors"
21-
"fmt"
2221
"io"
2322
"math/big"
2423
"os"
@@ -235,47 +234,40 @@ func (g *ShelleyGenesis) GenesisUtxos() ([]common.Utxo, error) {
235234

236235
// InitialPools returns all pools and their delegators from the genesis data
237236
func (g *ShelleyGenesis) InitialPools() (map[string]common.PoolRegistrationCertificate, map[string][]common.Address, error) {
238-
239237
pools := make(map[string]common.PoolRegistrationCertificate)
240238
poolStake := make(map[string][]common.Address)
241239

242-
// Check for empty staking data
243240
if reflect.DeepEqual(g.Staking, GenesisStaking{}) {
244241
return pools, poolStake, nil
245242
}
246243

247-
// Process stake delegations first
248244
for stakeAddr, poolId := range g.Staking.Stake {
249-
// Validate stake address format
250245
if len(stakeAddr) != 56 {
251-
return nil, nil, fmt.Errorf("invalid stake address length: %d (expected 56 hex chars)", len(stakeAddr))
246+
return nil, nil, errors.New("invalid stake address length")
252247
}
253248

254249
stakeKeyBytes, err := hex.DecodeString(stakeAddr)
255250
if err != nil {
256-
return nil, nil, fmt.Errorf("failed to decode stake key %s: %w", stakeAddr, err)
251+
return nil, nil, errors.New("failed to decode stake key")
257252
}
258253

259-
// Create stake address
260254
stakeAddrBytes := append([]byte{0xE1}, stakeKeyBytes...)
261255
addr, err := common.NewAddressFromBytes(stakeAddrBytes)
262256
if err != nil {
263-
return nil, nil, fmt.Errorf("failed to create stake address: %w", err)
257+
return nil, nil, errors.New("failed to create stake address")
264258
}
265259

266260
poolStake[poolId] = append(poolStake[poolId], addr)
267261
}
268262

269-
// Process pools
270263
for poolId, pool := range g.Staking.Pools {
271-
// Validate pool ID format
272264
if len(poolId) != 56 {
273-
return nil, nil, fmt.Errorf("invalid pool ID length: %d (expected 56 hex chars)", len(poolId))
265+
return nil, nil, errors.New("invalid pool ID length")
274266
}
275267

276268
operatorBytes, err := hex.DecodeString(poolId)
277269
if err != nil {
278-
return nil, nil, fmt.Errorf("failed to decode pool operator key: %w", err)
270+
return nil, nil, errors.New("failed to decode pool operator key")
279271
}
280272

281273
pools[poolId] = common.PoolRegistrationCertificate{
@@ -296,7 +288,6 @@ func (g *ShelleyGenesis) InitialPools() (map[string]common.PoolRegistrationCerti
296288

297289
// PoolById returns a specific pool by its ID along with its delegators
298290
func (g *ShelleyGenesis) PoolById(poolId string) (*common.PoolRegistrationCertificate, []common.Address, error) {
299-
// Validate input
300291
if len(poolId) != 56 {
301292
return nil, nil, errors.New("invalid pool ID length")
302293
}
@@ -306,7 +297,6 @@ func (g *ShelleyGenesis) PoolById(poolId string) (*common.PoolRegistrationCertif
306297
return nil, nil, errors.New("pool not found")
307298
}
308299

309-
// Decode pool operator key
310300
operatorBytes, err := hex.DecodeString(poolId)
311301
if err != nil {
312302
return nil, nil, errors.New("failed to decode pool operator key")
@@ -334,7 +324,6 @@ func (g *ShelleyGenesis) PoolById(poolId string) (*common.PoolRegistrationCertif
334324
}
335325
}
336326

337-
// Return pool with delegators
338327
return &common.PoolRegistrationCertificate{
339328
Operator: common.Blake2b224(operatorBytes),
340329
VrfKeyHash: pool.VrfKeyHash,

0 commit comments

Comments
 (0)