Skip to content

Commit

Permalink
feat: add Shelley protocol parameters support
Browse files Browse the repository at this point in the history
Signed-off-by: Ales Verbic <verbotenj@blinklabs.io>
  • Loading branch information
verbotenj committed Apr 17, 2024
1 parent aca581f commit 778a8cf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
46 changes: 45 additions & 1 deletion ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ type ShelleyTransactionBody struct {
Withdrawals cbor.Value `cbor:"5,keyasint,omitempty"`
Update struct {
cbor.StructAsArray
ProtocolParamUpdates cbor.Value
ProtocolParamUpdates map[Blake2b224]ShelleyProtocolParameterUpdate
Epoch uint64
} `cbor:"6,keyasint,omitempty"`
MetadataHash Blake2b256 `cbor:"7,keyasint,omitempty"`
Expand Down Expand Up @@ -397,6 +397,50 @@ func (t *ShelleyTransaction) Cbor() []byte {
return cborData
}

type ShelleyProtocolParameters struct {
cbor.StructAsArray
MinFeeA uint
MinFeeB uint
MaxBlockBodySize uint
MaxTxSize uint
MaxBlockHeaderSize uint
KeyDeposit uint
PoolDeposit uint
MaxEpoch uint
NOpt uint
A0 *cbor.Rat
Rho *cbor.Rat
Tau *cbor.Rat
Decentralization *cbor.Rat
Nonce *cbor.Rat
ProtocolMajor uint
ProtocolMinor uint
MinUtxoValue uint
}

type ShelleyProtocolParameterUpdate struct {
MinFeeA uint `cbor:"0,keyasint"`
MinFeeB uint `cbor:"1,keyasint"`
MaxBlockBodySize uint `cbor:"2,keyasint"`
MaxTxSize uint `cbor:"3,keyasint"`
MaxBlockHeaderSize uint `cbor:"4,keyasint"`
KeyDeposit uint `cbor:"5,keyasint"`
PoolDeposit uint `cbor:"6,keyasint"`
MaxEpoch uint `cbor:"7,keyasint"`
NOpt uint `cbor:"8,keyasint"`
A0 *cbor.Rat `cbor:"9,keyasint"`
Rho *cbor.Rat `cbor:"10,keyasint"`
Tau *cbor.Rat `cbor:"11,keyasint"`
Decentralization *cbor.Rat `cbor:"12,keyasint"`
Nonce *cbor.Rat `cbor:"13,keyasint"`
ProtocolVersion struct {
cbor.StructAsArray
Major uint
Minor uint
} `cbor:"14,keyasint"`
MinUtxoValue uint `cbor:"15,keyasint"`
}

func NewShelleyBlockFromCbor(data []byte) (*ShelleyBlock, error) {
var shelleyBlock ShelleyBlock
if _, err := cbor.Decode(data, &shelleyBlock); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions protocol/localstatequery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ func (c *Client) GetCurrentProtocolParams() (CurrentProtocolParamsResult, error)
return nil, err
}
return result[0], nil
case ledger.EraIdShelley:
result := []ledger.ShelleyProtocolParameters{}
if err := c.runQuery(query, &result); err != nil {
return nil, err
}
return result[0], nil
default:
result := []any{}
if err := c.runQuery(query, &result); err != nil {
Expand Down

0 comments on commit 778a8cf

Please sign in to comment.