Skip to content

Commit

Permalink
chore: move transaction interfaces to sub-package (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney committed Aug 25, 2024
1 parent f06c4f1 commit 30bba11
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 58 deletions.
76 changes: 76 additions & 0 deletions ledger/common/tx.go
Original file line number Diff line number Diff line change
@@ -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
}
66 changes: 8 additions & 58 deletions ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 30bba11

Please sign in to comment.