currency

package
v0.0.0-...-ff61ee7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2020 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const MaxParticipants = 100 // TODO
View Source
const MaxTxSize = 10000 // TODO

Variables

View Source
var ErrIntOverflow = fmt.Errorf("integer overflow")
View Source
var ErrInvalidReceiverCount = fmt.Errorf("receivers must match receivers array")
View Source
var ErrInvalidSenderCount = fmt.Errorf("senders must match send array")
View Source
var ErrInvalidSignatureCount = fmt.Errorf("signature array must match signer array")
View Source
var ErrInvalidTxCounter = fmt.Errorf("tx counter does not match account counter")
View Source
var ErrInvalidTxCounters = fmt.Errorf("tx counters array much match senders array")
View Source
var ErrInvalidTxMerkleRoot = fmt.Errorf("invalid tx Merkle root")
View Source
var ErrMustSignFirst = fmt.Errorf("must sign tx before encoding")
View Source
var ErrNoSend = fmt.Errorf("must send a at least 1 value")
View Source
var ErrNoSender = fmt.Errorf("must have at least one sender")
View Source
var ErrNonUniqueReceivers = fmt.Errorf("receivers not unique")
View Source
var ErrNonUniqueSenders = fmt.Errorf("senders not unique")
View Source
var ErrNotEnoughBalance = fmt.Errorf("account does not have enough balance")
View Source
var ErrNotEnoughSend = fmt.Errorf("receive amount exceeds send ammount")
View Source
var ErrSendersNotSorted = fmt.Errorf("senders must be sorted")
View Source
var ErrSignatureInvalid = fmt.Errorf("signature does not validate")
View Source
var ErrTooManyParticipants = fmt.Errorf("too many signatures")
View Source
var ErrTooManyTxInBlock = fmt.Errorf("too many transactions in block")
View Source
var ErrTxTooLarge = fmt.Errorf("tx too large")
View Source
var InitUniqueName = types.GetHash([]byte("should be some unique name"))

Functions

func InitCurrencyMemberChecker

func InitCurrencyMemberChecker(localRand *rand.Rand, rotateCord bool, rndMemberCount int,
	rndMemberType types.RndMemberType, localRandChangeFrequency types.ConsensusInt, priv sig.Priv,
	gc *generalconfig.GeneralConfig) consinterface.MemberChecker

func ValidateTransferTxFormat

func ValidateTransferTxFormat(tx *TransferTx) error

ValidateTransferTxFormat returns an error if the decoded transaction format contains any errors.

Types

type Account

type Account struct {
	Pub       sig.Pub
	TxCounter uint64
	Balance   uint64
}

func NewAccount

func NewAccount(pub sig.Pub) Account

type AccountStats

type AccountStats struct {
	MoneyTransfered         uint64
	TxConsumedCount         uint64
	FailedValidations       uint64
	PassedValidations       uint64
	GeneratedTxCount        uint64
	FailedGenerationTxCount uint64
}

func (*AccountStats) FailedGenerateTx

func (as *AccountStats) FailedGenerateTx()

func (*AccountStats) FailedValidation

func (as *AccountStats) FailedValidation()

func (*AccountStats) GenerateTx

func (as *AccountStats) GenerateTx()

func (*AccountStats) PassedValidation

func (as *AccountStats) PassedValidation()

func (*AccountStats) Reset

func (as *AccountStats) Reset()

func (AccountStats) StatsString

func (as AccountStats) StatsString(testDuration time.Duration) string

func (AccountStats) String

func (as AccountStats) String() string

type AccountTable

type AccountTable struct {
	// contains filtered or unexported fields
}

AccountTable provides operations to track a set of accounts. It is not concurrency safe.

func NewAccountTable

func NewAccountTable() *AccountTable

NewAccountTable generates an empty account table.

func (*AccountTable) ConsumeTx

func (at *AccountTable) ConsumeTx(tx *TransferTx, leftOverPub sig.Pub)

ConsumeTx consumes the transaction, sending any leftover sent money to leftOverPub. It should only be called after a transaction has validated correctly.

func (*AccountTable) Copy

func (at *AccountTable) Copy() *AccountTable

func (*AccountTable) DoneClear

func (at *AccountTable) DoneClear()

func (*AccountTable) DoneKeep

func (at *AccountTable) DoneKeep()

func (*AccountTable) GenerateTx

func (at *AccountTable) GenerateTx(senders sig.SortPriv, amounts []uint64,
	recipiants []sig.Pub, receiveAmounts []uint64) (tx *TransferTx, err error)

GenerateTx generates a transaction given the inputs. An error is returned if the generated transaction would be invalid.

func (*AccountTable) GetAccount

func (at *AccountTable) GetAccount(pub sig.Pub) (acc Account, err error)

GetAccount returns the account object for the given public key.

func (*AccountTable) GetAccountInfo

func (at *AccountTable) GetAccountInfo(pub sig.Pub) (txCounter, balance uint64, err error)

GetAccount info returns the transaction counter and balance of the account.

func (*AccountTable) Range

func (at *AccountTable) Range(f func(pub sig.PubKeyStr, acc Account) bool)

Range performs the func f over the accounts, it stops if f returns false. This should not modify the accounts.

func (*AccountTable) String

func (at *AccountTable) String() string

func (*AccountTable) UpdateAccount

func (at *AccountTable) UpdateAccount(pub sig.Pub, account Account)

func (*AccountTable) ValidateTx

func (at *AccountTable) ValidateTx(tx *TransferTx, validateSig bool, leftOverPub sig.Pub) (err error)

ValidateTx returns an error if the transaction is not valid. If validate sig is false then the transaction's signatures will not be validated. Unspent sent value would be sent to leftOverPub.

type CurrencyMemberChecker

type CurrencyMemberChecker struct {
	memberchecker.CustomMemberChecker
}

CurrencyMemberChecker is to be used with SimpleCurrencyTxProposer, it chooses the top memberCount members based on who owns the most currency.

func (*CurrencyMemberChecker) AddPubKeys

func (mc *CurrencyMemberChecker) AddPubKeys(fixedCoord sig.Pub, memberPubKeys, otherPubs sig.PubList, initRandBytes [32]byte,
	sh *consinterface.Shared)

AddPubKeys adds the pub keys as members to the consensus. Note that for the first consensus we use the pubs directly as given. In following rounds we take the top len(memberPubKeys) with the most currency as the members.

func (*CurrencyMemberChecker) AllowsChange

func (mc *CurrencyMemberChecker) AllowsChange() bool

AllowsChange returns true if the member checker allows changing members, used as a sanity check.

func (*CurrencyMemberChecker) New

New generates a new member checker for the index, this is called on the inital member checker each time.

func (*CurrencyMemberChecker) UpdateState

func (mc *CurrencyMemberChecker) UpdateState(fixedCoord sig.Pub, prevDec []byte, randBytes [32]byte,
	prevMember consinterface.MemberChecker, prevSM consinterface.GeneralStateMachineInterface,
	futureFixed types.ConsensusID) (newMemberPubs,
	newOtherPubs []sig.Pub, changedMembers bool)

UpdateState chooses the pub keys with the most currency as the next members (keeping the same number of members as the previous member checker)

type CurrencyStats

type CurrencyStats struct {
	AccStats  AccountStats
	PoolStats transactionsm.PoolStats
}

func (CurrencyStats) StatsString

func (cs CurrencyStats) StatsString(testDuration time.Duration) string

type InitBlock

type InitBlock struct {
	InitPubs       []sig.Pub       // The initial public keys.
	InitBalances   []uint64        // The initial balances.
	InitUniqueName types.HashBytes // Should be a unique string.
	NewPubFunc     func() sig.Pub  // Used during deserialization, should return an empty public key of the type being used.
}

InitBlock represents the initial balances and participants in the currency.

func (*InitBlock) Decode

func (ib *InitBlock) Decode(reader io.Reader) (n int, err error)

func (*InitBlock) Encode

func (ib *InitBlock) Encode(writer io.Writer) (n int, err error)

type SimpleCurrencyTxProposer

type SimpleCurrencyTxProposer struct {
	statemachine.AbsStateMachine
	statemachine.AbsRandSM
	// contains filtered or unexported fields
}

SimpleCurrencyTxProposer represents the statemachine object for the SimpleCons protocol, only this state machine can be used when testing this object.

func NewSimpleTxProposer

func NewSimpleTxProposer(useRand bool, initRandBytes [32]byte,
	initBlocksBytes [][]byte, myKeys []sig.Priv,
	newPubFunc func() sig.Pub, newSigFunc func() sig.Sig) *SimpleCurrencyTxProposer

NewSimpleTxProposer creates an empty SimpleCurrencyTxProposer object.

func (*SimpleCurrencyTxProposer) CheckDecisions

func (spi *SimpleCurrencyTxProposer) CheckDecisions(decs [][]byte) (outOforderErrors, errs []error)

CheckDecisions verifies that the decided values were valid.

func (*SimpleCurrencyTxProposer) DoneClear

func (spi *SimpleCurrencyTxProposer) DoneClear()

DoneClear should be called if the instance of the state machine will no longer be used (it should perform any cleanup).

func (*SimpleCurrencyTxProposer) DoneKeep

func (spi *SimpleCurrencyTxProposer) DoneKeep()

DoneKeep should be called if the instance of the state machine will be kept.

func (*SimpleCurrencyTxProposer) EndTest

func (spi *SimpleCurrencyTxProposer) EndTest()

func (*SimpleCurrencyTxProposer) GetByzProposal

func (spi *SimpleCurrencyTxProposer) GetByzProposal(originProposal []byte,
	_ *generalconfig.GeneralConfig) (byzProposal []byte)

GetByzProposal should generate a byzantine proposal based on the configuration

func (*SimpleCurrencyTxProposer) GetInitialState

func (spi *SimpleCurrencyTxProposer) GetInitialState() []byte

GetInitialState returns []byte("initial state")

func (*SimpleCurrencyTxProposer) GetProposal

func (spi *SimpleCurrencyTxProposer) GetProposal()

GetProposal is called when a consensus index is ready for a proposal. It should send the proposal for the consensus index by calling mainChannel.HasProposal().

func (*SimpleCurrencyTxProposer) GetSMStats

GetSMStats returns the statistics object for the SM.

func (*SimpleCurrencyTxProposer) HasDecided

func (spi *SimpleCurrencyTxProposer) HasDecided(proposer sig.Pub, nxt types.ConsensusInt, dec []byte)

HasDecided is called after the index nxt has decided.

func (*SimpleCurrencyTxProposer) Init

func (spi *SimpleCurrencyTxProposer) Init(gc *generalconfig.GeneralConfig, lastProposal types.ConsensusInt,
	needsConcurrent types.ConsensusInt, mainChannel channelinterface.MainChannel,
	doneChan chan channelinterface.ChannelCloseType, basicInit bool)

Init initalizes the simple proposal object state.

func (*SimpleCurrencyTxProposer) StartIndex

StartIndex is called when a consensus index is ready for a proposal. StartIndex is called when the previous consensus index has finished.

func (*SimpleCurrencyTxProposer) StatsString

func (spi *SimpleCurrencyTxProposer) StatsString(testDuration time.Duration) string

func (*SimpleCurrencyTxProposer) SubmitTransaction

func (spi *SimpleCurrencyTxProposer) SubmitTransaction(tx *TransferTx) error

Submits a transaction to the state machine.

func (*SimpleCurrencyTxProposer) ValidateProposal

func (spi *SimpleCurrencyTxProposer) ValidateProposal(proposer sig.Pub, dec []byte) (err error)

ValidateProposal should return true if the input proposal is valid.

type TransferTx

type TransferTx struct {
	Senders          sig.SortPub    // The keys sending the currency.
	Signatures       []sig.Sig      // The signatures of the senders (of the serialized transaction).
	SenderTxCounters []uint64       // The counter of how many transactions each sender has made.
	Recipiants       []sig.Pub      // The keys receiving the money.
	SendAmounts      []uint64       // The amount being sent from each sender.
	ReceiveAmounts   []uint64       // The amount being received at each receiver.
	SignedBytes      []byte         // The bytes to sign.
	NewPubFunc       func() sig.Pub // Used during deserialzation, should return an empty public key of the type being used.
	NewSigFunc       func() sig.Sig // Used during deserialization, should return an empty signature object of the key type being used.

}

TransferTx represents a transaction sending currency from one group of public keys to another.

func (*TransferTx) Decode

func (tx *TransferTx) Decode(reader io.Reader) (n int, err error)

Decode decodes the transaction into tx, returning the number of bytes read and any errors.

func (*TransferTx) Encode

func (tx *TransferTx) Encode(writer io.Writer) (n int, err error)

Encode encodes the transaction into writer, it returns the number of bytes written and any errors.

func (*TransferTx) GetConflictObjects

func (tx *TransferTx) GetConflictObjects() []transactionsm.ConflictObject

GetConflictObjects returns the pub keys.

func (*TransferTx) GetSignedHash

func (tx *TransferTx) GetSignedHash() types.HashBytes

GetSignedHash returns messages.GetHash(tx.GetSignedMessage())

func (*TransferTx) GetSignedMessage

func (tx *TransferTx) GetSignedMessage() []byte

GetSignedBytes returns the bytes that should be signed by the senders.

type TxBlock

type TxBlock struct {
	Index        types.ConsensusInt
	TxMerkleRoot merkle.MerkleRoot
	Transactions []*TransferTx
	PrevHash     types.HashBytes

	NewPubFunc func() sig.Pub
	NewSigFunc func() sig.Sig
}

func (*TxBlock) Decode

func (txl *TxBlock) Decode(reader io.Reader) (n int, err error)

func (*TxBlock) Encode

func (txl *TxBlock) Encode(writer io.Writer) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL