asset

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: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxAssetSize = 10000 // TODO

Variables

View Source
var ErrMustSignFirst = fmt.Errorf("must sign tx before encoding")
View Source
var InitUniqueName = types.GetHash([]byte(config.CsID))

Functions

func CheckDirectOutputFunc

func CheckDirectOutputFunc(_ *AssetAccount, inputs []AssetInterface, outputs []AssetInterface) error

func CheckUnique

func CheckUnique(assets []AssetInterface) error

func CheckValueOutputFunc

func CheckValueOutputFunc(account *AssetAccount, inputs []AssetInterface, outputs []AssetInterface) error

CheckValueOutputFunc checks that the inputs and outputs are valid.

func GenDirectAssetOutput

func GenDirectAssetOutput(_ *AssetAccount, assets []AssetInterface) (inputs []AssetInterface, outputs []AssetInterface)

genMultipleOutput takes as input the last asset of acc, outputs an output for each receiver.

func GenValueAssetOutput

func GenValueAssetOutput(acc *AssetAccount, assets []AssetInterface,
	receivers []sig.Pub, amounts []uint64) (inputs []AssetInterface, outputs []AssetInterface)

genValueAssetOutput generates value asset outputs given the inputs

Types

type AccountTable

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

func NewAccountTable

func NewAccountTable() *AccountTable

func (*AccountTable) ConsumeTransfer

func (at *AccountTable) ConsumeTransfer(tr *AssetTransfer)

func (*AccountTable) GenerateAssetTransfer

func (at *AccountTable) GenerateAssetTransfer(sender sig.Priv, inputAssets,
	outPuts []AssetInterface, recipiants []sig.Pub, checkFunc CheckTransferOutputFunc) (tx *AssetTransfer, err error)

GenerateAssetTransfer generates an asset transfer given the inputs. An error is returned if the generated transfer would be invalid.

func (*AccountTable) GetAccount

func (at *AccountTable) GetAccount(pub sig.Pub) (*AssetAccount, error)

GetAccount returns the account object for the given public key. A new account is allocated if one is not found.

func (*AccountTable) GetAccountInfo

func (at *AccountTable) GetAccountInfo(pub sig.Pub) (assetCount int, err error)

GetAccount info returns the number of assets held by the account.

func (*AccountTable) SendToSelf

func (at *AccountTable) SendToSelf(pub sig.Pub, hashes []types.HashBytes,
	sts SendToSelfAsset, tr *AssetTransfer) *AssetTransfer

func (*AccountTable) StartRecordingStats

func (at *AccountTable) StartRecordingStats()

func (*AccountTable) String

func (at *AccountTable) String() string

func (*AccountTable) ValidateTransfer

func (at *AccountTable) ValidateTransfer(tr *AssetTransfer, checkFunc CheckTransferOutputFunc, validateSig bool) (err error)

ValidateTransfer returns an error if the asset transfer is not valid. If validate sig is false then the transfer's signatures will not be validated.

type AssetAccount

type AssetAccount struct {
	Pub    sig.Pub
	Assets SortedAssets
}

func NewAssetAccount

func NewAssetAccount(pub sig.Pub) *AssetAccount

func (*AssetAccount) AddAsset

func (aa *AssetAccount) AddAsset(asset AssetInterface)

AddAsset adds the asset to the account.

func (*AssetAccount) CheckAssets

func (aa *AssetAccount) CheckAssets(toCheck []types.HashBytes) (ret []AssetInterface, err error)

CheckAssets returns the assets corresponding to the hashes at the account. Otherwise if the account does not have all the assets an error is returned.

func (*AssetAccount) ConsumeAssets

func (aa *AssetAccount) ConsumeAssets(assetIDs []types.HashBytes)

ConsumeAssets removes the assets from the account.

type AssetInterface

type AssetInterface interface {
	// GetOwner() sig.Pub
	GetID() types.HashBytes
	types.EncodeInterface
}

func DirectSendToSelf

func DirectSendToSelf(_ *AssetAccount, inputs []AssetInterface) (outputs []AssetInterface)

DirectSendToSelf returns the inputs as outputs with new hashes.

func GenInitialValueAssets

func GenInitialValueAssets(values []uint64, instanceID []byte) []AssetInterface

GenInitialValueAssets generates value assets for the initial inputs, instanceID is the unique id of the system (e.g. config.CSID).

func NewDirectAsset

func NewDirectAsset() AssetInterface

func NewValueAsset

func NewValueAsset() AssetInterface

func ValueSendToSelf

func ValueSendToSelf(account *AssetAccount, inputs []AssetInterface) (outputs []AssetInterface)

ValueSendToSelf returns the inputs as outputs with new hashes.

type AssetProposer

type AssetProposer struct {
	statemachine.AbsCausalStateMachine
	statemachine.AbsRandSM
	// contains filtered or unexported fields
}

AssetProposer represents the statemachine object for a causally ordered state machine making asset transfers.

func NewAssetProposer

func NewAssetProposer(useRand bool, initRandBytes [32]byte,
	initBlocksBytes [][]byte, myKey sig.Priv,
	newAssetFunc func() AssetInterface,
	newAssetTransferFunc func() *AssetTransfer,
	genAssetTransferFunc GenAssetTransferFunc,
	validFunc CheckTransferOutputFunc,
	sendtoSelf SendToSelfAsset, isMember bool, numMembers int,
	newPubFunc func() sig.Pub, newSigFunc func() sig.Sig) *AssetProposer

NewAssetProposer creates an empty AssetProposer object.

func (*AssetProposer) CheckDecisions

func (da *AssetProposer) CheckDecisions(root *utils.StringNode) (errors []error)

CheckDecisions is for testing and will be called at the end of the test with a causally ordered tree of all the decided values, it should then check if the decided values are valid.

func (*AssetProposer) DoneClear

func (da *AssetProposer) DoneClear()

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

func (*AssetProposer) DoneKeep

func (da *AssetProposer) DoneKeep()

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

func (*AssetProposer) FailAfter

func (da *AssetProposer) FailAfter(index types.ConsensusInt)

FailAfter is for testing, once index is reached, it should send a message on doneChan (the input from Init), telling the consensus to shutdown.

func (*AssetProposer) GenerateNewSM

GenerateNewSM is called on this init SM to generate a new SM given the items to be consumed. It should just generate the item, it should not change the state of any of the parentSMs. This will be called on the initial CausalStateMachineInterface passed to the system

func (*AssetProposer) GetByzProposal

func (da *AssetProposer) GetByzProposal(originProposal []byte,
	_ *generalconfig.GeneralConfig) (byzProposal []byte)

GetByzProposal should generate a byzantine proposal based on the configuration

func (*AssetProposer) GetDependentItems

func (da *AssetProposer) GetDependentItems() []sig.ConsIDPub

GetDependentItems returns a list of items dependent from this SM. This list must be the same as the list returned from HasDecided

func (*AssetProposer) GetInitialFirstIndex

func (da *AssetProposer) GetInitialFirstIndex() types.ConsensusID

GetInitialFirstIndex returns the hash of some unique string for the first instance of the state machine.

func (*AssetProposer) GetInitialState

func (da *AssetProposer) GetInitialState() []byte

GetInitialState returns the initial state of the program.

func (*AssetProposer) GetSMStats

func (da *AssetProposer) GetSMStats() consinterface.SMStats

GetSMStats returns the statistics object for the SM.

func (*AssetProposer) HasDecided

func (da *AssetProposer) HasDecided(proposer sig.Pub, index types.ConsensusIndex, owners []sig.Pub,
	decision []byte) (outputs []sig.ConsIDPub, updatedDecision []byte)

HasDecided is called each time a consensus decision takes place, given the index and the decided vaule. Proposer is the public key of the node that proposed the decision. It returns a list of causally dependent StateMachines that result from the decisions. If decision is nil, then the assets are sent back to the owner, and the updated decision reflecting this is returned.

func (*AssetProposer) Init

func (da *AssetProposer) Init(gc *generalconfig.GeneralConfig, endAfter types.ConsensusInt,
	memberCheckerState consinterface.ConsStateInterface, mainChannel channelinterface.MainChannel,
	doneChan chan channelinterface.ChannelCloseType, basicInit bool)

Init is called to initialize the object, lastProposal is the number of consensus instances to run, after which a message should be sent on doneChan telling the consensus to shut down.

func (*AssetProposer) StartInit

StartInit is called on the init state machine to start the program.

func (*AssetProposer) StatsString

func (da *AssetProposer) StatsString(testDuration time.Duration) string

StatsString returns statistics for the state machine.

func (*AssetProposer) ValidateProposal

func (da *AssetProposer) ValidateProposal(proposer sig.Pub, proposal []byte) error

ValidateProposal should return nil if the input proposal is valid, otherwise an error. Proposer is the public key of the node that proposed the value. It is called on the parent state machine instance of the proposal after it has decided.

type AssetStats

type AssetStats struct {
	AssetConsumedCount        uint64
	AssetGeneratedCount       uint64
	FailedAssetGeneratedCount uint64
	ValueTransferred          uint64
	FailedValidations         uint64
	PassedValidations         uint64
}

func (AssetStats) StatsString

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

func (AssetStats) String

func (as AssetStats) String() string

type AssetTransfer

type AssetTransfer struct {
	Sender    sig.Pub           // Who is sending the assets.
	Inputs    []types.HashBytes // The input assets.
	Outputs   []AssetInterface  // The output assets.
	Receivers []sig.Pub         // The receivers of the output assets.
	Signature sig.Sig           // The signature of the sender.

	// For encoding.
	NewAssetFunc func() AssetInterface
	NewSigFunc   func() sig.Sig
	NewPubFunc   func() sig.Pub
	SignedBytes  []byte // The bytes to sign.
}

func GenDirectAssetTransfer

func GenDirectAssetTransfer(priv sig.Priv, participants []sig.Pub, table *AccountTable) (tr *AssetTransfer)

func GenValueAssetTransfer

func GenValueAssetTransfer(priv sig.Priv, participants []sig.Pub, table *AccountTable) (tr *AssetTransfer)

func NewAssetTransfer

func NewAssetTransfer(sender sig.Pub, inputs []types.HashBytes, outputs []AssetInterface,
	receivers []sig.Pub) *AssetTransfer

func NewEmptyAssetTransfer

func NewEmptyAssetTransfer(newAssetFunc func() AssetInterface, newSigFunc func() sig.Sig,
	newPubFunc func() sig.Pub) *AssetTransfer

func (*AssetTransfer) CheckFormat

func (at *AssetTransfer) CheckFormat() error

func (*AssetTransfer) Decode

func (at *AssetTransfer) Decode(r io.Reader) (n int, err error)

Decode the asset transfer from the writer.

func (*AssetTransfer) Encode

func (at *AssetTransfer) Encode(writer io.Writer) (n int, err error)

Encode the asset transfer to the writer.

func (*AssetTransfer) GetSignedHash

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

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

func (*AssetTransfer) GetSignedMessage

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

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

func (*AssetTransfer) MarshalBinary

func (ba *AssetTransfer) MarshalBinary() (data []byte, err error)

Marshal the asset transfer.

func (*AssetTransfer) New

New creates an empty asset transfer object.

func (*AssetTransfer) UnmarshalBinary

func (ba *AssetTransfer) UnmarshalBinary(data []byte) error

Unmarshal the asset transfer.

type BaseAssetStats

type BaseAssetStats struct {
	AssetsTransfered uint64
	AssetStats
}

func (BaseAssetStats) StatsString

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

type BasicAsset

type BasicAsset struct {
	ID types.HashBytes
}

func NewBasicAsset

func NewBasicAsset(id types.HashBytes) *BasicAsset

func (*BasicAsset) Decode

func (ba *BasicAsset) Decode(reader io.Reader) (n int, err error)

Decode the asset from the reader.

func (*BasicAsset) Encode

func (ba *BasicAsset) Encode(writer io.Writer) (n int, err error)

Encode the the asset to the writer.

func (*BasicAsset) GetID

func (ba *BasicAsset) GetID() types.HashBytes

Return the hash id of the asset.

func (*BasicAsset) MarshalBinary

func (ba *BasicAsset) MarshalBinary() (data []byte, err error)

Marshal the asset.

func (*BasicAsset) New

func (ba *BasicAsset) New() types.EncodeInterface

New returns a new empty asset object.

func (*BasicAsset) UnmarshalBinary

func (ba *BasicAsset) UnmarshalBinary(data []byte) error

Unmarshal the asset.

type CheckTransferOutputFunc

type CheckTransferOutputFunc func(account *AssetAccount, inputs []AssetInterface, outputs []AssetInterface) error

CheckTransferOutputFunc is used to check if the given asset inputs and outputs for a transfer are valid.

type DirectAsset

type DirectAsset struct {
	BasicAsset
}

DirectAsset is a one-to-one input output

func CreateInitialDirectAsset

func CreateInitialDirectAsset(assetName []byte, instanceID []byte) *DirectAsset

Create initial direct asset should be called when the asset is first created, asset name is a unique name for the asset, instanceID the unique id of the system (e.g. config.CSID).

func (*DirectAsset) New

func (da *DirectAsset) New() types.EncodeInterface

type GenAssetTransferFunc

type GenAssetTransferFunc func(priv sig.Priv, participants []sig.Pub, table *AccountTable) (tr *AssetTransfer)

GenAssetTransferFunc is called during the experiment each time a new transfer asset is needed. It returns nil if there is no assets to transfer.

type InitBlock

type InitBlock struct {
	InitPubs       []sig.Pub // The initial public keys.
	InitAssets     []AssetInterface
	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.
	NewAssetFunc   func() AssetInterface // Used to deserialize the assets
}

InitAssetBlock represents the initial assets.

func NewInitBlock

func NewInitBlock(initPubs []sig.Pub, initAssets []AssetInterface, initUniqueName string) *InitBlock

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 SendToSelfAsset

type SendToSelfAsset func(account *AssetAccount, inputs []AssetInterface) []AssetInterface

SendToSelfAsset is used when a nil value is decided, so the asset should just be sent back to the owner with a new ID

type SortedAssets

type SortedAssets []AssetInterface

SortedAssests is a list of assets that can be sorted.

func (SortedAssets) Len

func (sa SortedAssets) Len() int

func (SortedAssets) Less

func (sa SortedAssets) Less(i, j int) bool

func (SortedAssets) Swap

func (sa SortedAssets) Swap(i, j int)

type ValueAsset

type ValueAsset struct {
	BasicAsset
	Value uint64
}

ValueAsset is an asset that also contains a value.

func InternalNewValueAsset

func InternalNewValueAsset(value uint64, pid uint64, instanceID []byte) *ValueAsset

func (*ValueAsset) Decode

func (ba *ValueAsset) Decode(reader io.Reader) (n int, err error)

Decode the asset from the reader.

func (*ValueAsset) Encode

func (va *ValueAsset) Encode(writer io.Writer) (n int, err error)

Encode the asset to the writer.

func (*ValueAsset) MarshalBinary

func (ba *ValueAsset) MarshalBinary() (data []byte, err error)

Marshal the asset.

func (*ValueAsset) New

func (va *ValueAsset) New() types.EncodeInterface

func (*ValueAsset) UnmarshalBinary

func (ba *ValueAsset) UnmarshalBinary(data []byte) error

Unmarshal the asset.

Jump to

Keyboard shortcuts

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