Skip to content

Commit

Permalink
feat: TX staking withdrawals support (#623)
Browse files Browse the repository at this point in the history
This adds support for decoding and retrieving staking withdrawals from a TX

Fixes #332
  • Loading branch information
agaffney authored May 14, 2024
1 parent e72fabc commit d54d92a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func (t AllegraTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}

func (t AllegraTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t AllegraTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ func (t AlonzoTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}

func (t AlonzoTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t AlonzoTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ func (t BabbageTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}

func (t BabbageTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t BabbageTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
5 changes: 5 additions & 0 deletions ledger/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ func (t *ByronTransaction) Certificates() []Certificate {
return nil
}

func (t *ByronTransaction) Withdrawals() map[*Address]uint64 {
// No withdrawals in Byron
return nil
}

func (t *ByronTransaction) Metadata() *cbor.Value {
return t.Attributes
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ func (t ConwayTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}

func (t ConwayTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t ConwayTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func (t MaryTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}

func (t MaryTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t MaryTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
15 changes: 10 additions & 5 deletions ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,8 @@ type ShelleyTransactionBody struct {
TxFee uint64 `cbor:"2,keyasint,omitempty"`
Ttl uint64 `cbor:"3,keyasint,omitempty"`
TxCertificates []CertificateWrapper `cbor:"4,keyasint,omitempty"`
// TODO: figure out how to parse this correctly
// We keep the raw CBOR because it can contain a map with []byte keys, which
// Go does not allow
Withdrawals cbor.Value `cbor:"5,keyasint,omitempty"`
Update struct {
TxWithdrawals map[*Address]uint64 `cbor:"5,keyasint,omitempty"`
Update struct {
cbor.StructAsArray
ProtocolParamUpdates map[Blake2b224]ShelleyProtocolParameterUpdate
Epoch uint64
Expand Down Expand Up @@ -243,6 +240,10 @@ func (b *ShelleyTransactionBody) Certificates() []Certificate {
return ret
}

func (b *ShelleyTransactionBody) Withdrawals() map[*Address]uint64 {
return b.TxWithdrawals
}

func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx {
var txi []*utxorpc.TxInput
var txo []*utxorpc.TxOutput
Expand Down Expand Up @@ -397,6 +398,10 @@ func (t ShelleyTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}

func (t ShelleyTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t ShelleyTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
1 change: 1 addition & 0 deletions ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type TransactionBody interface {
CollateralReturn() TransactionOutput
TotalCollateral() uint64
Certificates() []Certificate
Withdrawals() map[*Address]uint64
Utxorpc() *utxorpc.Tx
}

Expand Down

0 comments on commit d54d92a

Please sign in to comment.