Skip to content

Commit 30bba11

Browse files
authored
chore: move transaction interfaces to sub-package (#693)
1 parent f06c4f1 commit 30bba11

File tree

2 files changed

+84
-58
lines changed

2 files changed

+84
-58
lines changed

ledger/common/tx.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2024 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package common
16+
17+
import (
18+
"github.com/blinklabs-io/gouroboros/cbor"
19+
20+
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
21+
)
22+
23+
type Transaction interface {
24+
TransactionBody
25+
Metadata() *cbor.LazyValue
26+
IsValid() bool
27+
Consumed() []TransactionInput
28+
Produced() []Utxo
29+
}
30+
31+
type TransactionBody interface {
32+
Cbor() []byte
33+
Fee() uint64
34+
Hash() string
35+
Inputs() []TransactionInput
36+
Outputs() []TransactionOutput
37+
TTL() uint64
38+
ProtocolParametersUpdate() map[Blake2b224]any
39+
ValidityIntervalStart() uint64
40+
ReferenceInputs() []TransactionInput
41+
Collateral() []TransactionInput
42+
CollateralReturn() TransactionOutput
43+
TotalCollateral() uint64
44+
Certificates() []Certificate
45+
Withdrawals() map[*Address]uint64
46+
AuxDataHash() *Blake2b256
47+
RequiredSigners() []Blake2b224
48+
AssetMint() *MultiAsset[MultiAssetTypeMint]
49+
ScriptDataHash() *Blake2b256
50+
VotingProcedures() VotingProcedures
51+
ProposalProcedures() []ProposalProcedure
52+
CurrentTreasuryValue() int64
53+
Donation() uint64
54+
Utxorpc() *utxorpc.Tx
55+
}
56+
57+
type TransactionInput interface {
58+
Id() Blake2b256
59+
Index() uint32
60+
Utxorpc() *utxorpc.TxInput
61+
}
62+
63+
type TransactionOutput interface {
64+
Address() Address
65+
Amount() uint64
66+
Assets() *MultiAsset[MultiAssetTypeOutput]
67+
Datum() *cbor.LazyValue
68+
DatumHash() *Blake2b256
69+
Cbor() []byte
70+
Utxorpc() *utxorpc.TxOutput
71+
}
72+
73+
type Utxo struct {
74+
Id TransactionInput
75+
Output TransactionOutput
76+
}

ledger/tx.go

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,17 @@ import (
1818
"encoding/hex"
1919
"fmt"
2020

21-
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
22-
"golang.org/x/crypto/blake2b"
23-
24-
"github.com/blinklabs-io/gouroboros/cbor"
2521
"github.com/blinklabs-io/gouroboros/ledger/common"
26-
)
27-
28-
type Transaction interface {
29-
TransactionBody
30-
Metadata() *cbor.LazyValue
31-
IsValid() bool
32-
Consumed() []TransactionInput
33-
Produced() []Utxo
34-
}
35-
36-
type TransactionBody interface {
37-
Cbor() []byte
38-
Fee() uint64
39-
Hash() string
40-
Inputs() []TransactionInput
41-
Outputs() []TransactionOutput
42-
TTL() uint64
43-
ProtocolParametersUpdate() map[Blake2b224]any
44-
ValidityIntervalStart() uint64
45-
ReferenceInputs() []TransactionInput
46-
Collateral() []TransactionInput
47-
CollateralReturn() TransactionOutput
48-
TotalCollateral() uint64
49-
Certificates() []Certificate
50-
Withdrawals() map[*Address]uint64
51-
AuxDataHash() *Blake2b256
52-
RequiredSigners() []Blake2b224
53-
AssetMint() *common.MultiAsset[common.MultiAssetTypeMint]
54-
ScriptDataHash() *Blake2b256
55-
VotingProcedures() VotingProcedures
56-
ProposalProcedures() []ProposalProcedure
57-
CurrentTreasuryValue() int64
58-
Donation() uint64
59-
Utxorpc() *utxorpc.Tx
60-
}
6122

62-
type TransactionInput interface {
63-
Id() Blake2b256
64-
Index() uint32
65-
Utxorpc() *utxorpc.TxInput
66-
}
67-
68-
type TransactionOutput interface {
69-
Address() Address
70-
Amount() uint64
71-
Assets() *common.MultiAsset[common.MultiAssetTypeOutput]
72-
Datum() *cbor.LazyValue
73-
DatumHash() *Blake2b256
74-
Cbor() []byte
75-
Utxorpc() *utxorpc.TxOutput
76-
}
23+
"golang.org/x/crypto/blake2b"
24+
)
7725

78-
type Utxo struct {
79-
Id TransactionInput
80-
Output TransactionOutput
81-
}
26+
// Compatablity aliases
27+
type Transaction = common.Transaction
28+
type TransactionBody = common.TransactionBody
29+
type TransactionInput = common.TransactionInput
30+
type TransactionOutput = common.TransactionOutput
31+
type Utxo = common.Utxo
8232

8333
func NewTransactionFromCbor(txType uint, data []byte) (Transaction, error) {
8434
switch txType {

0 commit comments

Comments
 (0)