diff --git a/ledger/common/tx.go b/ledger/common/tx.go new file mode 100644 index 0000000..7e1992d --- /dev/null +++ b/ledger/common/tx.go @@ -0,0 +1,76 @@ +// Copyright 2024 Blink Labs Software +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package common + +import ( + "github.com/blinklabs-io/gouroboros/cbor" + + utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" +) + +type Transaction interface { + TransactionBody + Metadata() *cbor.LazyValue + IsValid() bool + Consumed() []TransactionInput + Produced() []Utxo +} + +type TransactionBody interface { + Cbor() []byte + Fee() uint64 + Hash() string + Inputs() []TransactionInput + Outputs() []TransactionOutput + TTL() uint64 + ProtocolParametersUpdate() map[Blake2b224]any + ValidityIntervalStart() uint64 + ReferenceInputs() []TransactionInput + Collateral() []TransactionInput + CollateralReturn() TransactionOutput + TotalCollateral() uint64 + Certificates() []Certificate + Withdrawals() map[*Address]uint64 + AuxDataHash() *Blake2b256 + RequiredSigners() []Blake2b224 + AssetMint() *MultiAsset[MultiAssetTypeMint] + ScriptDataHash() *Blake2b256 + VotingProcedures() VotingProcedures + ProposalProcedures() []ProposalProcedure + CurrentTreasuryValue() int64 + Donation() uint64 + Utxorpc() *utxorpc.Tx +} + +type TransactionInput interface { + Id() Blake2b256 + Index() uint32 + Utxorpc() *utxorpc.TxInput +} + +type TransactionOutput interface { + Address() Address + Amount() uint64 + Assets() *MultiAsset[MultiAssetTypeOutput] + Datum() *cbor.LazyValue + DatumHash() *Blake2b256 + Cbor() []byte + Utxorpc() *utxorpc.TxOutput +} + +type Utxo struct { + Id TransactionInput + Output TransactionOutput +} diff --git a/ledger/tx.go b/ledger/tx.go index 256f60b..eff131b 100644 --- a/ledger/tx.go +++ b/ledger/tx.go @@ -18,67 +18,17 @@ import ( "encoding/hex" "fmt" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" - "golang.org/x/crypto/blake2b" - - "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/common" -) - -type Transaction interface { - TransactionBody - Metadata() *cbor.LazyValue - IsValid() bool - Consumed() []TransactionInput - Produced() []Utxo -} - -type TransactionBody interface { - Cbor() []byte - Fee() uint64 - Hash() string - Inputs() []TransactionInput - Outputs() []TransactionOutput - TTL() uint64 - ProtocolParametersUpdate() map[Blake2b224]any - ValidityIntervalStart() uint64 - ReferenceInputs() []TransactionInput - Collateral() []TransactionInput - CollateralReturn() TransactionOutput - TotalCollateral() uint64 - Certificates() []Certificate - Withdrawals() map[*Address]uint64 - AuxDataHash() *Blake2b256 - RequiredSigners() []Blake2b224 - AssetMint() *common.MultiAsset[common.MultiAssetTypeMint] - ScriptDataHash() *Blake2b256 - VotingProcedures() VotingProcedures - ProposalProcedures() []ProposalProcedure - CurrentTreasuryValue() int64 - Donation() uint64 - Utxorpc() *utxorpc.Tx -} -type TransactionInput interface { - Id() Blake2b256 - Index() uint32 - Utxorpc() *utxorpc.TxInput -} - -type TransactionOutput interface { - Address() Address - Amount() uint64 - Assets() *common.MultiAsset[common.MultiAssetTypeOutput] - Datum() *cbor.LazyValue - DatumHash() *Blake2b256 - Cbor() []byte - Utxorpc() *utxorpc.TxOutput -} + "golang.org/x/crypto/blake2b" +) -type Utxo struct { - Id TransactionInput - Output TransactionOutput -} +// Compatablity aliases +type Transaction = common.Transaction +type TransactionBody = common.TransactionBody +type TransactionInput = common.TransactionInput +type TransactionOutput = common.TransactionOutput +type Utxo = common.Utxo func NewTransactionFromCbor(txType uint, data []byte) (Transaction, error) { switch txType {