types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2017 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 22

Documentation

Index

Constants

View Source
const (
	EntityTypeCHByte        = byte(0x01)
	EntityTypeGCMByte       = byte(0x02)
	EntityTypeICMByte       = byte(0x03)
	EntityTypeCustodianByte = byte(0x04)
)

EntityType byte identifiers

View Source
const (
	PermTransferTx = Perm(1 << iota)
	PermCreateAccountTx
	PermCreateLegalEntityTx
	PermCreateUserTx
	PermNone = Perm(0)
)

Each permission listed below reprent a respective transaction.

View Source
const (
	// TxTypeCreateAccount defines CreateAccountTx's code
	TxTypeCreateAccount = byte(0x02)
)
View Source
const (
	// TxTypeCreateLegalEntity defines CreateLegalEntityTx's code
	TxTypeCreateLegalEntity = byte(0x03)
)
View Source
const (
	// TxTypeCreateUser defines CreateUserTx's code
	TxTypeCreateUser = byte(0x04)
)
View Source
const (
	// TxTypeTransfer defines TrasferTx's code
	TxTypeTransfer = byte(0x01)
)

Variables

View Source
var (
	// Currencies contains the in-memory database of supported currencies
	Currencies map[string]ConcreteCurrency
)

Functions

func CanExecTx

func CanExecTx(executor TxExecutor, tx Tx) bool

CanExecTx is a convenience function that validates caller's execution permission on a Tx.

func IsValidEntityType

func IsValidEntityType(b byte) bool

IsValidEntityType checks whether a byte is a valid type for an entity.

func SignTx

func SignTx(signedBytes []byte, addr []byte, privKey crypto.PrivKey) (crypto.Signature, error)

SignTx signs the transaction if its address and the privateKey's one match.

Types

type Account

type Account struct {
	ID       string   `json:"id"`        // Account's address
	EntityID string   `json:"entity_id"` // Account's owner
	Wallets  []Wallet `json:"wallets"`   // Account's wallets
}

Account defines the attributes of an account

func NewAccount

func NewAccount(id, entityID string) *Account

NewAccount creates a new account.

func (*Account) BelongsTo

func (acc *Account) BelongsTo(legalEntityID string) bool

BelongsTo checks whether an Account belongs to a given LegalEntity

func (*Account) Copy

func (acc *Account) Copy() *Account

Copy make a copy of an Account

func (*Account) Equal

func (acc *Account) Equal(a *Account) bool

Equal provides an equality operator

func (*Account) GetWallet

func (acc *Account) GetWallet(currency string) *Wallet

GetWallet retrieves the Account's wallet for the given currency.

func (*Account) SetWallet

func (account *Account) SetWallet(wallet Wallet)

func (*Account) String

func (acc *Account) String() string

type AccountGetter

type AccountGetter interface {
	GetAccount(id string) *Account
}

AccountGetter is implemented by any value that has a GetAccount

type AccountGetterSetter

type AccountGetterSetter interface {
	GetAccount(id string) *Account
	SetAccount(id string, acc *Account)
}

AccountGetterSetter is implemented by any value that has both GetAccount and SetAccount

type AccountIndex

type AccountIndex struct {
	Accounts []string `json:"accounts"`
}

AccountIndex stores the list of accounts managed on the ledger.

func NewAccountIndex

func NewAccountIndex() *AccountIndex

NewAccountIndex creates a new accounts index

func (*AccountIndex) Add

func (i *AccountIndex) Add(s string)

Add adds an account to the index, if it's not yet there.

func (*AccountIndex) Has

func (i *AccountIndex) Has(s string) bool

Has returns whether s is listed in the accounts index.

func (*AccountIndex) ToStringSlice

func (i *AccountIndex) ToStringSlice() []string

ToStringSlice returns a string slice representation of the index.

type AccountIndexGetter

type AccountIndexGetter interface {
	GetAccountIndex() *AccountIndex
}

AccountIndexGetter is implemented by any value that has a GetAccountIndex

type AccountIndexGetterSetter

type AccountIndexGetterSetter interface {
	GetAccountIndex() *AccountIndex
	SetAccountIndex(i *AccountIndex)
}

AccountIndexGetterSetter is implemented by any value that has both GetAccountIndex and SetAccountIndex

type AccountIndexSetter

type AccountIndexSetter interface {
	SetAccountIndex(i *AccountIndex)
}

AccountIndexSetter is implemented by any value that has a SetAccountIndex

type AccountSetter

type AccountSetter interface {
	SetAccount(id string, acc *Account)
}

AccountSetter is implemented by any value that has a SetAccount

type AccountsReturned

type AccountsReturned struct {
	Account []*Account `json:"accounts"`
}

AccountsReturned defines the attributes of response's payload

type ConcreteCurrency

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

ConcreteCurrency defines the attributes of a concrete currency type

func (ConcreteCurrency) DecimalPlaces

func (c ConcreteCurrency) DecimalPlaces() uint

DecimalPlaces returns the number of decimals of the currency

func (ConcreteCurrency) MinimumUnit

func (c ConcreteCurrency) MinimumUnit() int64

MinimumUnit returns the minimum amount for the currency

func (ConcreteCurrency) Symbol

func (c ConcreteCurrency) Symbol() string

Symbol returns the 3-letter ISO 4217 code

func (ConcreteCurrency) ValidateAmount

func (c ConcreteCurrency) ValidateAmount(amount int64) bool

ValidateAmount checks whether an amount is valid for the currency

type CreateAccountTx

type CreateAccountTx struct {
	Address   []byte           `json:"address"`    // Hash of the user's PubKey
	AccountID string           `json:"account_id"` // ID of the new account
	Signature crypto.Signature `json:"signature"`
}

CreateAccountTx defines the attributes of an account create.

func (*CreateAccountTx) SignBytes

func (tx *CreateAccountTx) SignBytes(chainID string) []byte

SignBytes generates a byte-to-byte signature

func (*CreateAccountTx) SignTx

func (tx *CreateAccountTx) SignTx(privateKey crypto.PrivKey, chainID string) error

SignTx signs the transaction if its address and the privateKey's one match.

func (*CreateAccountTx) String

func (tx *CreateAccountTx) String() string

func (*CreateAccountTx) TxType

func (tx *CreateAccountTx) TxType() byte

TxType returns the byte type of CreateAccountTx

func (*CreateAccountTx) ValidateBasic

func (tx *CreateAccountTx) ValidateBasic() abci.Result

ValidateBasic performs basic validation on the Tx.

type CreateLegalEntityTx

type CreateLegalEntityTx struct {
	Address   []byte           `json:"address"`   // Hash of the user's PubKey
	EntityID  string           `json:"entity_id"` // ID of the new legal entity
	ParentID  string           `json:"parent_id"` // ID of the new legal entity's parent
	Type      byte             `json:"type"`      // Mandatory
	Name      string           `json:"name"`      // Could be empty
	Signature crypto.Signature `json:"signature"`
}

CreateLegalEntityTx defines the attributes of a legal entity create.

func (*CreateLegalEntityTx) SignBytes

func (tx *CreateLegalEntityTx) SignBytes(chainID string) []byte

SignBytes generates a byte-to-byte signature

func (*CreateLegalEntityTx) SignTx

func (tx *CreateLegalEntityTx) SignTx(privateKey crypto.PrivKey, chainID string) error

SignTx signs the transaction if its address and the privateKey's one match.

func (*CreateLegalEntityTx) String

func (tx *CreateLegalEntityTx) String() string

func (*CreateLegalEntityTx) TxType

func (tx *CreateLegalEntityTx) TxType() byte

TxType returns the byte type of CreateLegalEntityTx

func (*CreateLegalEntityTx) ValidateBasic

func (tx *CreateLegalEntityTx) ValidateBasic() abci.Result

ValidateBasic performs basic validation on the Tx.

type CreateUserTx

type CreateUserTx struct {
	Address   []byte           `json:"address"`    // Hash of the user's PubKey
	Name      string           `json:"name"`       // Human-readable identifier, mandatory
	PubKey    crypto.PubKey    `json:"pub_key"`    // New user's public key
	CanCreate bool             `json:"can_create"` // Whether the user is a super user or not
	Signature crypto.Signature `json:"signature"`
}

CreateUserTx defines the attributes of a user create.

func (*CreateUserTx) SignBytes

func (tx *CreateUserTx) SignBytes(chainID string) []byte

SignBytes generates a byte-to-byte signature

func (*CreateUserTx) SignTx

func (tx *CreateUserTx) SignTx(privateKey crypto.PrivKey, chainID string) error

SignTx signs the transaction if its address and the privateKey's one match.

func (*CreateUserTx) String

func (tx *CreateUserTx) String() string

func (*CreateUserTx) TxType

func (tx *CreateUserTx) TxType() byte

TxType returns the byte type of CreateUserTx

func (*CreateUserTx) ValidateBasic

func (tx *CreateUserTx) ValidateBasic() abci.Result

ValidateBasic performs basic validation on the Tx.

type Currency

type Currency interface {
	Symbol() string
	DecimalPlaces() uint
	MinimumUnit() int64
	ValidateAmount(int64) bool
}

Currency represents a support currency type

type Index

type Index interface {
	Has(s string) bool
	ToStringSlice() []string
	Add(s string)
}

Index defines the operations that can be performed on an objects index.

type LegalEntitiesReturned

type LegalEntitiesReturned struct {
	LegalEntities []*LegalEntity `json:"legal_entities"`
}

type LegalEntity

type LegalEntity struct {
	ID          string `json:"id"`           // LegalEntity's ID
	EntityID    string `json:"entity_id"`    // LegalEntity's owner
	Type        byte   `json:"type"`         // Mandatory
	Name        string `json:"name"`         // This could be empty
	Permissions Perm   `json:"permissions"`  // Set of allowed Txs
	CreatorAddr []byte `json:"creator_addr"` // ID of the creator of the Clearing House that created the legal entity
}

LegalEntity defines the attributes of a legal entity

func NewCH

func NewCH(id string, name string, creatorAddr []byte, EntityID string) *LegalEntity

NewCH is a convenience function to create a new CH

func NewCustodian

func NewCustodian(id string, name string, creatorAddr []byte, EntityID string) *LegalEntity

NewCustodian is a convenience function to create a new Custodian

func NewGCM

func NewGCM(id string, name string, creatorAddr []byte, EntityID string) *LegalEntity

NewGCM is a convenience function to create a new GCM

func NewICM

func NewICM(id string, name string, creatorAddr []byte, EntityID string) *LegalEntity

NewICM is a convenience function to create a new ICM

func NewLegalEntity

func NewLegalEntity(id string, t byte, name string, permissions Perm, creatorAddr []byte, EntityID string) *LegalEntity

NewLegalEntity initializes a new LegalEntity

func NewLegalEntityByType

func NewLegalEntityByType(t byte, id string, name string, creatorAddr []byte, EntityID string) *LegalEntity

NewLegalEntityByType is a convenience function to create a legal entity according to the type given.

func (*LegalEntity) CanExecTx

func (l *LegalEntity) CanExecTx(txType byte) bool

CanExecTx determines whether a LegalEntity can execute a Tx

func (*LegalEntity) Equal

func (l *LegalEntity) Equal(e *LegalEntity) bool

Equal provides an equality operator

func (*LegalEntity) String

func (l *LegalEntity) String() string

type LegalEntityGetter

type LegalEntityGetter interface {
	GetLegalEntity(id string) *LegalEntity
}

LegalEntityGetter is implemented by any value that has a GetLegalEntity

type LegalEntityGetterSetter

type LegalEntityGetterSetter interface {
	GetLegalEntity(id string) *LegalEntity
	SetLegalEntity(id string, acc *LegalEntity)
}

LegalEntityGetterSetter is implemented by any value that has both GetLegalEntity and SetLegalEntity

type LegalEntityIndex

type LegalEntityIndex struct {
	Ids []string `json:"ids"`
}

func (*LegalEntityIndex) Add

func (i *LegalEntityIndex) Add(s string)

func (*LegalEntityIndex) Has

func (i *LegalEntityIndex) Has(s string) bool

type LegalEntitySetter

type LegalEntitySetter interface {
	SetLegalEntity(id string, acc *LegalEntity)
}

LegalEntitySetter is implemented by any value that has a SetLegalEntity

type Perm

type Perm uint64

Perm is a synonym of uint64

func NewPermByTxType

func NewPermByTxType(bs ...byte) Perm

NewPermByTxType creates a Perm object by ORing the Tx respective permissions.

func (Perm) Add

func (p Perm) Add(perms Perm) Perm

Add returns p | perms

func (Perm) Clear

func (p Perm) Clear(perms Perm) Perm

Clear returns p & (p ^ perms), in fact disabling p's bits given in perms.

func (Perm) Has

func (p Perm) Has(perms Perm) bool

Has returns (p & perms) != 0

type PrivUser

type PrivUser struct {
	crypto.PrivKey
	User
}

PrivUser defines the attributes of a private user

type SignedTx

type SignedTx interface {
	TxType() byte
	SignBytes(chainID string) []byte
	SignTx(privateKey crypto.PrivKey, chainID string) error
}

SignedTx extends Tx with a method to generate signatures.

type TransferTx

type TransferTx struct {
	Committer      TxTransferCommitter       `json:"committer"`
	Sender         TxTransferSender          `json:"sender"`
	Recipient      TxTransferRecipient       `json:"recipient"`
	CounterSigners []TxTransferCounterSigner `json:"counter_signers"`
}

TransferTx defines the attributes of transfer transaction

func (*TransferTx) SetSignature

func (tx *TransferTx) SetSignature(addr []byte, sig crypto.Signature) bool

SetSignature sets account's signature to the relevant TxInputTransfer

func (*TransferTx) SignBytes

func (tx *TransferTx) SignBytes(chainID string) []byte

SignBytes generates a byte-to-byte signature

func (*TransferTx) SignTx

func (tx *TransferTx) SignTx(privateKey crypto.PrivKey, chainID string) error

SignTx signs the transaction if its address and the privateKey's one match.

func (*TransferTx) String

func (tx *TransferTx) String() string

func (*TransferTx) TxType

func (tx *TransferTx) TxType() byte

TxType returns the byte type of TransferTx

func (*TransferTx) ValidateBasic

func (tx *TransferTx) ValidateBasic() (res abci.Result)

ValidateBasic validates Tx basic structure.

type Tx

type Tx interface {
	TxType() byte
	SignBytes(chainID string) []byte
}

Tx (Transaction) is an atomic operation on the ledger state.

type TxBasicValidator

type TxBasicValidator interface {
	ValidateBasic() abci.Result
}

TxBasicValidator implements basic validation rules.

type TxExecutor

type TxExecutor interface {
	CanExecTx(byte) bool
}

TxExecutor validates Tx execution permission

type TxTransferCommitter

type TxTransferCommitter struct {
	Address   []byte           `json:"address"` // Hash of the user's PubKey
	Signature crypto.Signature `json:"signature"`
}

TxTransferCommitter defines the attributes of a transfer's sender

func (TxTransferCommitter) SignBytes

func (t TxTransferCommitter) SignBytes(chainID string) []byte

SignBytes generates a byte-to-byte signature.

func (*TxTransferCommitter) SignTx

func (t *TxTransferCommitter) SignTx(privateKey crypto.PrivKey, chainID string) error

SignTx signs the transaction if its address and the privateKey's one match.

func (TxTransferCommitter) String

func (t TxTransferCommitter) String() string

String returns a string representation of TxTransferCommitter

func (TxTransferCommitter) ValidateBasic

func (t TxTransferCommitter) ValidateBasic() abci.Result

ValidateBasic performs basic validation on a TxInputTransfer

type TxTransferCounterSigner

type TxTransferCounterSigner struct {
	Address   []byte           `json:"address"` // Hash of the user's PubKey
	Signature crypto.Signature `json:"signature"`
}

TxTransferCounterSigner defines the attributes of a transfer's counter signer

func (TxTransferCounterSigner) SignBytes

func (t TxTransferCounterSigner) SignBytes(chainID string) []byte

SignBytes generates a byte-to-byte signature.

func (*TxTransferCounterSigner) SignTx

func (t *TxTransferCounterSigner) SignTx(privateKey crypto.PrivKey, chainID string) error

SignTx signs the transaction if its address and the privateKey's one match.

func (TxTransferCounterSigner) String

func (t TxTransferCounterSigner) String() string

String returns a string representation of TxTransferCounterSigner

func (TxTransferCounterSigner) ValidateBasic

func (t TxTransferCounterSigner) ValidateBasic() abci.Result

ValidateBasic performs basic validation on a TxTransferCounterSigner

type TxTransferRecipient

type TxTransferRecipient struct {
	AccountID string `json:"account_id"` // Recipient's Account ID
}

TxTransferRecipient defines the attributes of a transfer's recipient

func (TxTransferRecipient) String

func (t TxTransferRecipient) String() string

String returns a string representation of TxInputTransfer

func (TxTransferRecipient) ValidateBasic

func (t TxTransferRecipient) ValidateBasic() abci.Result

ValidateBasic performs basic validation on a TxTransferRecipient

type TxTransferSender

type TxTransferSender struct {
	AccountID string `json:"account_id"` // Sender's Account ID
	Amount    int64  `json:"amount"`
	Currency  string `json:"currency"` //3-letter ISO 4217 code or ""
	Sequence  int    `json:"sequence"` // Must be 1 greater than the last committed TxInput or 0 if the account is just a countersigner
}

TxTransferSender defines the attributes of a transfer's sender

func (TxTransferSender) String

func (t TxTransferSender) String() string

String returns a string representation of TxTransferSender

func (TxTransferSender) ValidateBasic

func (t TxTransferSender) ValidateBasic() abci.Result

ValidateBasic performs basic validation on a TxInputTransfer

type User

type User struct {
	PubKey      crypto.PubKey `json:"pub_key"`     // May be nil, if not known.
	Name        string        `json:"name"`        // Human-readable identifier, mandatory
	EntityID    string        `json:"entity_id"`   // LegalEntity's ID
	Permissions Perm          `json:"permissions"` // User is disabled if empty
}

User defines the attribute of a ledger's user

func NewUser

func NewUser(pubKey crypto.PubKey, name string, entityID string, permissions Perm) *User

NewUser initializes a new user

func (*User) CanExecTx

func (u *User) CanExecTx(txType byte) bool

CanExecTx determines whether a LegalEntity can execute a Tx

func (*User) Equal

func (u *User) Equal(v *User) bool

Equal provides an equality operator

func (*User) String

func (u *User) String() string

func (*User) VerifySignature

func (u *User) VerifySignature(signBytes []byte, signature crypto.Signature) bool

VerifySignature verifies a signed message against the User's PubKey.

type UserGetter

type UserGetter interface {
	GetUser(addr []byte) *User
}

UserGetter is implemented by any value that has a GetUser

type UserGetterSetter

type UserGetterSetter interface {
	GetUser(addr []byte) *User
	SetUser(addr []byte, acc *User)
}

UserGetterSetter is implemented by any value that has both GetUser and SetUser

type UserSetter

type UserSetter interface {
	SetUser(addr []byte, acc *User)
}

UserSetter is implemented by any value that has a SetUser

type Wallet

type Wallet struct {
	Currency string `json:"currency"`
	Balance  int64  `json:"balance"`
	Sequence int    `json:"sequence"`
}

Wallet defines the attributes of an account's wallet

func (*Wallet) Equal

func (w *Wallet) Equal(z *Wallet) bool

Equal provides an equality operator

func (*Wallet) String

func (w *Wallet) String() string

Jump to

Keyboard shortcuts

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