Skip to content

Commit 9dbe90e

Browse files
authored
Merge pull request #406 from blinklabs-io/feat/ledger-issuer-vkey-pool
feat: better support for issuer vkey
2 parents 23c5d12 + da2aca7 commit 9dbe90e

File tree

9 files changed

+40
-16
lines changed

9 files changed

+40
-16
lines changed

cmd/block-fetch/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ func main() {
8585
fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", v.Era().Name, v.SlotNumber(), v.BlockNumber(), v.Hash())
8686
}
8787
if f.all {
88+
issuerVkey := block.IssuerVkey()
89+
fmt.Printf("\nMinted by: %s (%s)\n", issuerVkey.PoolId(), issuerVkey.Hash())
8890
// Display transaction info
8991
fmt.Printf("\nTransactions:\n")
9092
for _, tx := range block.Transactions() {

ledger/allegra.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (b *AllegraBlock) SlotNumber() uint64 {
5555
return b.Header.SlotNumber()
5656
}
5757

58-
func (b *AllegraBlock) IssuerVkey() []byte {
58+
func (b *AllegraBlock) IssuerVkey() IssuerVkey {
5959
return b.Header.IssuerVkey()
6060
}
6161

ledger/alonzo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (b *AlonzoBlock) SlotNumber() uint64 {
5757
return b.Header.SlotNumber()
5858
}
5959

60-
func (b *AlonzoBlock) IssuerVkey() []byte {
60+
func (b *AlonzoBlock) IssuerVkey() IssuerVkey {
6161
return b.Header.IssuerVkey()
6262
}
6363

ledger/babbage.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (b *BabbageBlock) SlotNumber() uint64 {
5757
return b.Header.SlotNumber()
5858
}
5959

60-
func (b *BabbageBlock) IssuerVkey() []byte {
60+
func (b *BabbageBlock) IssuerVkey() IssuerVkey {
6161
return b.Header.IssuerVkey()
6262
}
6363

@@ -99,7 +99,7 @@ type BabbageBlockHeader struct {
9999
BlockNumber uint64
100100
Slot uint64
101101
PrevHash Blake2b256
102-
IssuerVkey []byte
102+
IssuerVkey IssuerVkey
103103
VrfKey []byte
104104
VrfResult interface{}
105105
BlockBodySize uint64
@@ -139,7 +139,7 @@ func (h *BabbageBlockHeader) SlotNumber() uint64 {
139139
return h.Body.Slot
140140
}
141141

142-
func (h *BabbageBlockHeader) IssuerVkey() []byte {
142+
func (h *BabbageBlockHeader) IssuerVkey() IssuerVkey {
143143
return h.Body.IssuerVkey
144144
}
145145

ledger/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type BlockHeader interface {
3030
Hash() string
3131
BlockNumber() uint64
3232
SlotNumber() uint64
33-
IssuerVkey() []byte
33+
IssuerVkey() IssuerVkey
3434
BlockBodySize() uint64
3535
Era() Era
3636
Cbor() []byte

ledger/byron.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ func (h *ByronMainBlockHeader) SlotNumber() uint64 {
9696
return uint64((h.ConsensusData.SlotId.Epoch * ByronSlotsPerEpoch) + uint64(h.ConsensusData.SlotId.Slot))
9797
}
9898

99-
func (h *ByronMainBlockHeader) IssuerVkey() []byte {
99+
func (h *ByronMainBlockHeader) IssuerVkey() IssuerVkey {
100100
// Byron blocks don't have an issuer
101-
return nil
101+
return IssuerVkey([]byte{})
102102
}
103103

104104
func (h *ByronMainBlockHeader) BlockBodySize() uint64 {
@@ -203,9 +203,9 @@ func (h *ByronEpochBoundaryBlockHeader) SlotNumber() uint64 {
203203
return uint64(h.ConsensusData.Epoch * ByronSlotsPerEpoch)
204204
}
205205

206-
func (h *ByronEpochBoundaryBlockHeader) IssuerVkey() []byte {
206+
func (h *ByronEpochBoundaryBlockHeader) IssuerVkey() IssuerVkey {
207207
// Byron blocks don't have an issuer
208-
return nil
208+
return IssuerVkey([]byte{})
209209
}
210210

211211
func (h *ByronEpochBoundaryBlockHeader) BlockBodySize() uint64 {
@@ -241,7 +241,7 @@ func (b *ByronMainBlock) SlotNumber() uint64 {
241241
return b.Header.SlotNumber()
242242
}
243243

244-
func (b *ByronMainBlock) IssuerVkey() []byte {
244+
func (b *ByronMainBlock) IssuerVkey() IssuerVkey {
245245
return b.Header.IssuerVkey()
246246
}
247247

@@ -282,7 +282,7 @@ func (b *ByronEpochBoundaryBlock) SlotNumber() uint64 {
282282
return b.Header.SlotNumber()
283283
}
284284

285-
func (b *ByronEpochBoundaryBlock) IssuerVkey() []byte {
285+
func (b *ByronEpochBoundaryBlock) IssuerVkey() IssuerVkey {
286286
return b.Header.IssuerVkey()
287287
}
288288

ledger/common.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,25 @@ func (a Address) String() string {
322322
func (a Address) MarshalJSON() ([]byte, error) {
323323
return []byte(`"` + a.String() + `"`), nil
324324
}
325+
326+
// IssuerVkey represents the verification key for the stake pool that minted a block
327+
type IssuerVkey [32]byte
328+
329+
func (i IssuerVkey) Hash() Blake2b224 {
330+
hash, _ := blake2b.New(28, nil)
331+
hash.Write(i[:])
332+
return Blake2b224(hash.Sum(nil))
333+
}
334+
335+
func (i IssuerVkey) PoolId() string {
336+
// Convert data to base32 and encode as bech32
337+
convData, err := bech32.ConvertBits(i.Hash().Bytes(), 8, 5, true)
338+
if err != nil {
339+
panic(fmt.Sprintf("unexpected error converting data to base32: %s", err))
340+
}
341+
encoded, err := bech32.Encode("pool", convData)
342+
if err != nil {
343+
panic(fmt.Sprintf("unexpected error encoding data as bech32: %s", err))
344+
}
345+
return encoded
346+
}

ledger/mary.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (b *MaryBlock) SlotNumber() uint64 {
5656
return b.Header.SlotNumber()
5757
}
5858

59-
func (b *MaryBlock) IssuerVkey() []byte {
59+
func (b *MaryBlock) IssuerVkey() IssuerVkey {
6060
return b.Header.IssuerVkey()
6161
}
6262

ledger/shelley.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (b *ShelleyBlock) SlotNumber() uint64 {
5555
return b.Header.SlotNumber()
5656
}
5757

58-
func (b *ShelleyBlock) IssuerVkey() []byte {
58+
func (b *ShelleyBlock) IssuerVkey() IssuerVkey {
5959
return b.Header.IssuerVkey()
6060
}
6161

@@ -89,7 +89,7 @@ type ShelleyBlockHeader struct {
8989
BlockNumber uint64
9090
Slot uint64
9191
PrevHash Blake2b256
92-
IssuerVkey []byte
92+
IssuerVkey IssuerVkey
9393
VrfKey []byte
9494
NonceVrf interface{}
9595
LeaderVrf interface{}
@@ -124,7 +124,7 @@ func (h *ShelleyBlockHeader) SlotNumber() uint64 {
124124
return h.Body.Slot
125125
}
126126

127-
func (h *ShelleyBlockHeader) IssuerVkey() []byte {
127+
func (h *ShelleyBlockHeader) IssuerVkey() IssuerVkey {
128128
return h.Body.IssuerVkey
129129
}
130130

0 commit comments

Comments
 (0)