Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,50 @@ func (h *AllegraBlockHeader) Era() common.Era {
}

type AllegraTransactionBody struct {
shelley.ShelleyTransactionBody
Update struct {
common.TransactionBodyBase
TxInputs shelley.ShelleyTransactionInputSet `cbor:"0,keyasint,omitempty"`
TxOutputs []shelley.ShelleyTransactionOutput `cbor:"1,keyasint,omitempty"`
TxFee uint64 `cbor:"2,keyasint,omitempty"`
Ttl uint64 `cbor:"3,keyasint,omitempty"`
TxCertificates []common.CertificateWrapper `cbor:"4,keyasint,omitempty"`
TxWithdrawals map[*common.Address]uint64 `cbor:"5,keyasint,omitempty"`
Update struct {
cbor.StructAsArray
ProtocolParamUpdates map[common.Blake2b224]AllegraProtocolParameterUpdate
Epoch uint64
} `cbor:"6,keyasint,omitempty"`
TxValidityIntervalStart uint64 `cbor:"8,keyasint,omitempty"`
TxAuxDataHash *common.Blake2b256 `cbor:"7,keyasint,omitempty"`
TxValidityIntervalStart uint64 `cbor:"8,keyasint,omitempty"`
}

func (b *AllegraTransactionBody) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (b *AllegraTransactionBody) Inputs() []common.TransactionInput {
ret := []common.TransactionInput{}
for _, input := range b.TxInputs.Items() {
ret = append(ret, input)
}
return ret
}

func (b *AllegraTransactionBody) Outputs() []common.TransactionOutput {
ret := []common.TransactionOutput{}
for _, output := range b.TxOutputs {
ret = append(ret, &output)
}
return ret
}

func (b *AllegraTransactionBody) Fee() uint64 {
return b.TxFee
}

func (b *AllegraTransactionBody) TTL() uint64 {
return b.Ttl
}

func (b *AllegraTransactionBody) ValidityIntervalStart() uint64 {
return b.TxValidityIntervalStart
}
Expand All @@ -160,6 +191,26 @@ func (b *AllegraTransactionBody) ProtocolParameterUpdates() (uint64, map[common.
return b.Update.Epoch, updateMap
}

func (b *AllegraTransactionBody) Certificates() []common.Certificate {
ret := make([]common.Certificate, len(b.TxCertificates))
for i, cert := range b.TxCertificates {
ret[i] = cert.Certificate
}
return ret
}

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

func (b *AllegraTransactionBody) AuxDataHash() *common.Blake2b256 {
return b.TxAuxDataHash
}

func (b *AllegraTransactionBody) Utxorpc() *utxorpc.Tx {
return common.TransactionBodyToUtxorpc(b)
}

type AllegraTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down
64 changes: 25 additions & 39 deletions ledger/allegra/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,12 @@ func TestUtxoValidateOutsideValidityIntervalUtxo(t *testing.T) {
func TestUtxoValidateInputSetEmptyUtxo(t *testing.T) {
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
TxInputs: shelley.NewShelleyTransactionInputSet(
// Non-empty input set
[]shelley.ShelleyTransactionInput{
{},
},
),
},
TxInputs: shelley.NewShelleyTransactionInputSet(
// Non-empty input set
[]shelley.ShelleyTransactionInput{
{},
},
),
},
}
testLedgerState := test.MockLedgerState{}
Expand Down Expand Up @@ -200,9 +198,7 @@ func TestUtxoValidateFeeTooSmallUtxo(t *testing.T) {
testTxCbor, _ := hex.DecodeString("abcdef")
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
TxFee: testExactFee,
},
TxFee: testExactFee,
},
}
testTx.SetCbor(testTxCbor)
Expand Down Expand Up @@ -369,11 +365,9 @@ func TestUtxoValidateWrongNetwork(t *testing.T) {
)
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
TxOutputs: []shelley.ShelleyTransactionOutput{
{
OutputAmount: 123456,
},
TxOutputs: []shelley.ShelleyTransactionOutput{
{
OutputAmount: 123456,
},
},
},
Expand Down Expand Up @@ -441,9 +435,7 @@ func TestUtxoValidateWrongNetworkWithdrawal(t *testing.T) {
)
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
TxWithdrawals: map[*common.Address]uint64{},
},
TxWithdrawals: map[*common.Address]uint64{},
},
}
testLedgerState := test.MockLedgerState{
Expand Down Expand Up @@ -510,17 +502,15 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
testOutputOverAmount := testOutputExactAmount + 999
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
TxFee: testFee,
TxInputs: shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{
shelley.NewShelleyTransactionInput(testInputTxId, 0),
},
),
TxOutputs: []shelley.ShelleyTransactionOutput{
// Empty placeholder output
{},
TxFee: testFee,
TxInputs: shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{
shelley.NewShelleyTransactionInput(testInputTxId, 0),
},
),
TxOutputs: []shelley.ShelleyTransactionOutput{
// Empty placeholder output
{},
},
},
}
Expand Down Expand Up @@ -676,11 +666,9 @@ func TestUtxoValidateOutputTooSmallUtxo(t *testing.T) {
var testOutputAmountBad uint64 = 123
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
TxOutputs: []shelley.ShelleyTransactionOutput{
// Empty placeholder output
{},
},
TxOutputs: []shelley.ShelleyTransactionOutput{
// Empty placeholder output
{},
},
},
}
Expand Down Expand Up @@ -763,11 +751,9 @@ func TestUtxoValidateOutputBootAddrAttrsTooBig(t *testing.T) {
)
testTx := &allegra.AllegraTransaction{
Body: allegra.AllegraTransactionBody{
ShelleyTransactionBody: shelley.ShelleyTransactionBody{
TxOutputs: []shelley.ShelleyTransactionOutput{
// Empty placeholder
{},
},
TxOutputs: []shelley.ShelleyTransactionOutput{
// Empty placeholder
{},
},
},
}
Expand Down
66 changes: 59 additions & 7 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,39 @@ func (h *AlonzoBlockHeader) Era() common.Era {
}

type AlonzoTransactionBody struct {
mary.MaryTransactionBody
TxOutputs []AlonzoTransactionOutput `cbor:"1,keyasint,omitempty"`
Update struct {
common.TransactionBodyBase
TxInputs shelley.ShelleyTransactionInputSet `cbor:"0,keyasint,omitempty"`
TxOutputs []AlonzoTransactionOutput `cbor:"1,keyasint,omitempty"`
TxFee uint64 `cbor:"2,keyasint,omitempty"`
Ttl uint64 `cbor:"3,keyasint,omitempty"`
TxCertificates []common.CertificateWrapper `cbor:"4,keyasint,omitempty"`
TxWithdrawals map[*common.Address]uint64 `cbor:"5,keyasint,omitempty"`
Update struct {
cbor.StructAsArray
ProtocolParamUpdates map[common.Blake2b224]AlonzoProtocolParameterUpdate
Epoch uint64
} `cbor:"6,keyasint,omitempty"`
TxScriptDataHash *common.Blake2b256 `cbor:"11,keyasint,omitempty"`
TxCollateral []shelley.ShelleyTransactionInput `cbor:"13,keyasint,omitempty"`
TxRequiredSigners []common.Blake2b224 `cbor:"14,keyasint,omitempty"`
NetworkId uint8 `cbor:"15,keyasint,omitempty"`
TxAuxDataHash *common.Blake2b256 `cbor:"7,keyasint,omitempty"`
TxValidityIntervalStart uint64 `cbor:"8,keyasint,omitempty"`
TxMint *common.MultiAsset[common.MultiAssetTypeMint] `cbor:"9,keyasint,omitempty"`
TxScriptDataHash *common.Blake2b256 `cbor:"11,keyasint,omitempty"`
TxCollateral []shelley.ShelleyTransactionInput `cbor:"13,keyasint,omitempty"`
TxRequiredSigners []common.Blake2b224 `cbor:"14,keyasint,omitempty"`
NetworkId uint8 `cbor:"15,keyasint,omitempty"`
}

func (b *AlonzoTransactionBody) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (b *AlonzoTransactionBody) Inputs() []common.TransactionInput {
ret := []common.TransactionInput{}
for _, input := range b.TxInputs.Items() {
ret = append(ret, input)
}
return ret
}

func (b *AlonzoTransactionBody) Outputs() []common.TransactionOutput {
ret := []common.TransactionOutput{}
for _, output := range b.TxOutputs {
Expand All @@ -169,6 +185,18 @@ func (b *AlonzoTransactionBody) Outputs() []common.TransactionOutput {
return ret
}

func (b *AlonzoTransactionBody) Fee() uint64 {
return b.TxFee
}

func (b *AlonzoTransactionBody) TTL() uint64 {
return b.Ttl
}

func (b *AlonzoTransactionBody) ValidityIntervalStart() uint64 {
return b.TxValidityIntervalStart
}

func (b *AlonzoTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
for k, v := range b.Update.ProtocolParamUpdates {
Expand All @@ -177,6 +205,26 @@ func (b *AlonzoTransactionBody) ProtocolParameterUpdates() (uint64, map[common.B
return b.Update.Epoch, updateMap
}

func (b *AlonzoTransactionBody) Certificates() []common.Certificate {
ret := make([]common.Certificate, len(b.TxCertificates))
for i, cert := range b.TxCertificates {
ret[i] = cert.Certificate
}
return ret
}

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

func (b *AlonzoTransactionBody) AuxDataHash() *common.Blake2b256 {
return b.TxAuxDataHash
}

func (b *AlonzoTransactionBody) AssetMint() *common.MultiAsset[common.MultiAssetTypeMint] {
return b.TxMint
}

func (b *AlonzoTransactionBody) Collateral() []common.TransactionInput {
ret := []common.TransactionInput{}
for _, collateral := range b.TxCollateral {
Expand All @@ -193,6 +241,10 @@ func (b *AlonzoTransactionBody) ScriptDataHash() *common.Blake2b256 {
return b.TxScriptDataHash
}

func (b *AlonzoTransactionBody) Utxorpc() *utxorpc.Tx {
return common.TransactionBodyToUtxorpc(b)
}

type AlonzoTransactionOutput struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down
Loading
Loading