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
23 changes: 23 additions & 0 deletions ledger/common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ func (a *Address) MarshalCBOR() ([]byte, error) {
return cbor.Encode(addrBytes)
}

func (a Address) NetworkId() uint {
if a.addressType == AddressTypeByron {
if a.byronAddressAttr.Network == nil {
return AddressNetworkMainnet
}
return uint(*a.byronAddressAttr.Network)
} else {
return uint(a.networkId)
}
}

func (a Address) Type() uint8 {
return a.addressType
}

func (a Address) ByronType() uint64 {
return a.byronAddressType
}

// PaymentAddress returns a new Address with only the payment address portion. This will return nil for anything other than payment and script addresses
func (a Address) PaymentAddress() *Address {
var addrType uint8
Expand Down Expand Up @@ -337,6 +356,10 @@ func (a *Address) StakeKeyHash() Blake2b224 {
return Blake2b224(a.stakingAddress[:])
}

func (a *Address) ByronAttr() ByronAddressAttributes {
return a.byronAddressAttr
}

func (a Address) generateHRP() string {
var ret string
if a.addressType == AddressTypeNoneKey ||
Expand Down
3 changes: 2 additions & 1 deletion ledger/common/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

// UtxoState defines the interface for querying the UTxO state
type UtxoState interface {
UtxosById([]TransactionInput) ([]Utxo, error)
UtxoById(TransactionInput) (Utxo, error)
}

// CertState defines the interface for querying the certificate state
Expand All @@ -30,6 +30,7 @@ type CertState interface{}
type LedgerState interface {
UtxoState
CertState
NetworkId() uint
}

// TipState defines the interface for querying the current tip
Expand Down
1 change: 1 addition & 0 deletions ledger/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type TransactionBody interface {
type TransactionInput interface {
Id() Blake2b256
Index() uint32
String() string
Utxorpc() *utxorpc.TxInput
}

Expand Down
129 changes: 128 additions & 1 deletion ledger/shelley/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

package shelley

import "fmt"
import (
"fmt"
"strings"

"github.com/blinklabs-io/gouroboros/ledger/common"
)

type ExpiredUtxoError struct {
Ttl uint64
Expand All @@ -28,3 +33,125 @@ func (e ExpiredUtxoError) Error() string {
e.Slot,
)
}

type InputSetEmptyUtxoError struct{}

func (InputSetEmptyUtxoError) Error() string {
return "input set empty"
}

type FeeTooSmallUtxoError struct {
Provided uint64
Min uint64
}

func (e FeeTooSmallUtxoError) Error() string {
return fmt.Sprintf(
"fee too small: provided %d, minimum %d",
e.Provided,
e.Min,
)
}

type BadInputsUtxoError struct {
Inputs []common.TransactionInput
}

func (e BadInputsUtxoError) Error() string {
tmpInputs := make([]string, 0, len(e.Inputs))
for idx, tmpInput := range e.Inputs {
tmpInputs[idx] = tmpInput.String()
}
return fmt.Sprintf(
"bad input(s): %s",
strings.Join(tmpInputs, ", "),
)
}

type WrongNetworkError struct {
NetId uint
Addrs []common.Address
}

func (e WrongNetworkError) Error() string {
tmpAddrs := make([]string, 0, len(e.Addrs))
for idx, tmpAddr := range e.Addrs {
tmpAddrs[idx] = tmpAddr.String()
}
return fmt.Sprintf(
"wrong network: %s",
strings.Join(tmpAddrs, ", "),
)
}

type WrongNetworkWithdrawalError struct {
NetId uint
Addrs []common.Address
}

func (e WrongNetworkWithdrawalError) Error() string {
tmpAddrs := make([]string, 0, len(e.Addrs))
for idx, tmpAddr := range e.Addrs {
tmpAddrs[idx] = tmpAddr.String()
}
return fmt.Sprintf(
"wrong network withdrawals: %s",
strings.Join(tmpAddrs, ", "),
)
}

type ValueNotConservedUtxoError struct {
Consumed uint64
Produced uint64
}

func (e ValueNotConservedUtxoError) Error() string {
return fmt.Sprintf(
"value not conserved: consumed %d, produced %d",
e.Consumed,
e.Produced,
)
}

type OutputTooSmallUtxoError struct {
Outputs []common.TransactionOutput
}

func (e OutputTooSmallUtxoError) Error() string {
tmpOutputs := make([]string, 0, len(e.Outputs))
for idx, tmpOutput := range e.Outputs {
tmpOutputs[idx] = fmt.Sprintf("%#v", tmpOutput)
}
return fmt.Sprintf(
"output too small: %s",
strings.Join(tmpOutputs, ", "),
)
}

type OutputBootAddrAttrsTooBigError struct {
Outputs []common.TransactionOutput
}

func (e OutputBootAddrAttrsTooBigError) Error() string {
tmpOutputs := make([]string, 0, len(e.Outputs))
for idx, tmpOutput := range e.Outputs {
tmpOutputs[idx] = fmt.Sprintf("%#v", tmpOutput)
}
return fmt.Sprintf(
"output bootstrap address attributes too big: %s",
strings.Join(tmpOutputs, ", "),
)
}

type MaxTxSizeUtxoError struct {
TxSize uint
MaxTxSize uint
}

func (e MaxTxSizeUtxoError) Error() string {
return fmt.Sprintf(
"transaction size too large: size %d, max %d",
e.TxSize,
e.MaxTxSize,
)
}
Loading