pt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: GPL-3.0 Imports: 10 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HashNew      = sha256.New
	SigningCurve = btcec.S256()
)
View Source
var (
	ZeroHash Hash
	ZeroSign Sign
)

Hash "nil" values for compare operations

View Source
var (
	ErrInvalidHash = errors.New("invalid hash string")
	ErrInvalidSign = errors.New("invalid sign string")
)

Parse errors

Functions

func VerifyTransferHash

func VerifyTransferHash(sign Sign, transferHash Hash, publicKey *btcec.PublicKey) error

Types

type AccID

type AccID uint64

AccID is an unique account id.

func (AccID) String

func (id AccID) String() string

type BigChain

type BigChain interface {
	Fetch(ctx context.Context, accID AccID, limit int) ([]Txn, *Settings, error)
}

BigChain is an global reliable storage for transactions and settings. It's is the only point of truth. In case of possible inconsistency all local account data is erased and refetched from BigChain.

type Chain

type Chain interface {
	ListUnspentTxns(accID AccID) []Txn
	PutTo(accID AccID, txns []Txn)
	GetLastHash(accID AccID) Hash
	GetBalance(accID AccID) int64
	GetLastTxn(accID AccID) *Txn
	GetLastNTxns(accID AccID, n int) []Txn
	Reset(AccID)
}

Chain is an local cache of last account transaftions. It's used to process new transfers fast.

type Hash

type Hash [32]byte

func GetHash

func GetHash(h hash.Hash, txn *Txn) Hash

func GetHashDefault

func GetHashDefault(txn *Txn) Hash

func GetHashFromString

func GetHashFromString(s string) (Hash, error)

func GetSettingsHash

func GetSettingsHash(h hash.Hash, s *Settings) Hash

func GetSettingsHashDefault

func GetSettingsHashDefault(s *Settings) Hash

func GetSettingsRequestHash

func GetSettingsRequestHash(h hash.Hash, s *Settings) Hash

func GetSettingsRequestHashDefault

func GetSettingsRequestHashDefault(s *Settings) Hash

func GetTransferHash

func GetTransferHash(h hash.Hash, t Transfer) Hash

func GetTransferHashDefault

func GetTransferHashDefault(t Transfer) Hash

func HashFromString

func HashFromString(s string) Hash

func (Hash) String

func (th Hash) String() string

type ID

type ID uint64

ID is an transaction or settings id. It goes from 1 and up for each account, separate for transactions and settings.

type Preloader

type Preloader interface {
	Preload(context.Context, AccID) error
	Reset(context.Context, AccID)
}

Preloader loads the most recent account data from reliable storage. It dosn't fetch data if it was fetched before and wasn't Reset

type PublicKey

type PublicKey []byte

func ParsePubKey

func ParsePubKey(s string) (PublicKey, error)

func (PublicKey) BTCECKey

func (k PublicKey) BTCECKey() (*btcec.PublicKey, error)

func (PublicKey) String

func (k PublicKey) String() string

type Pusher

type Pusher interface {
	Push(ctx context.Context, txns []Txn) error
}

Pusher is an general transfer pusher mechanism. It's used to push data to global storage, receiver's node, third parties and so on.

type Router

type Router interface {
	// Returns host which is responsible for given key.
	// Key usually is an AccountID
	GetHostByKey(key string) string
	// All nodes hostnames of the cluster
	Nodes() []string
	// Sets cluster nodes
	SetNodes(nodes []string)
	// Checks if given node is our own, so we must process request not redirect it
	IsSelf(node string) bool
}

Router is an cluster router. It's used to find node which is responsible for processing transactions of given account.

type Settings

type Settings struct {
	ID                 ID
	Account            AccID
	PublicKey          PublicKey
	PrevHash, Hash     Hash
	VerifyTransferSign bool
	DataHash           Hash
	Sign               Sign
}

Settings is an account settings. Settings are form the similar chain as Txns are.

type SettingsChain

type SettingsChain interface {
	GetLastSettings(AccID) *Settings
	GetLastHash(AccID) Hash
	Put(*Settings)
	Reset(AccID)
}

type SettingsID

type SettingsID struct {
	AccID
	ID
}

SettingsID is an unique ID for each settings among all accounts.

func NewSettingsID

func NewSettingsID(acc AccID, id ID) SettingsID

func (SettingsID) String

func (t SettingsID) String() string

type SettingsProcessor

type SettingsProcessor interface {
	ProcessSettings(ctx context.Context, s *Settings) (SettingsResult, error)
	GetLastSettings(ctx context.Context, acc AccID) (*Settings, error)
}

type SettingsPusher

type SettingsPusher interface {
	PushSettings(ctx context.Context, sett *Settings) error
}

Settings pusher is the same thing as Pusher but for Settings.

type SettingsResult

type SettingsResult struct {
	SettingsID SettingsID // Last Settings ID
	Hash       Hash       // Hash Settings Hash
}

SettingsResult is an result of settings change.

type Sign

type Sign [72]byte

func GetSignFromString

func GetSignFromString(s string) (Sign, error)

func SignFromString

func SignFromString(s string) Sign

func SignTransfer

func SignTransfer(transferHash Hash, privKey *btcec.PrivateKey) (Sign, error)

func (Sign) String

func (s Sign) String() string

type Transfer

type Transfer struct {
	Sender     AccID
	Batch      []*TransferItem // Receivers and amounts
	Sign       Sign            // Request sign. It will be kept at first transaction of the batch
	PrevHash   Hash            // Hash of last output transaction for Sender account
	SettingsID ID              // Current account settings ID for Sender account
}

Transfer is an request to make transfer from an account to one or many others.

func NewSingleTransfer

func NewSingleTransfer(sender, receiver AccID, amount int64) Transfer

func (*Transfer) AddReceiver

func (t *Transfer) AddReceiver(receiver AccID, amount int64)

type TransferItem

type TransferItem struct {
	Receiver AccID
	Amount   int64
}

TransferItem is an part of Transfer request.

type TransferProcessor

type TransferProcessor interface {
	ProcessTransfer(ctx context.Context, t Transfer) (TransferResult, error)
	GetPrevHash(ctx context.Context, acc AccID) (Hash, error)
	GetBalance(ctx context.Context, acc AccID) (int64, error)
	SetPusher(Pusher)
	SetPreloader(Preloader)
	SetSettingsChain(SettingsChain)
}

type TransferResult

type TransferResult struct {
	TxnID      TxnID // TxnID of the first transaction in the batch
	Hash       Hash  // Hash of last transaction in the batch
	SettingsId ID    // Current settings ID
}

TransferResult is an result of transfer.

type Txn

type Txn struct {
	// Account incremental id for output transactions.
	ID               ID
	Sender, Receiver AccID
	Amount           int64
	// Balance of the Sender account at the time just after this transaction has been processed.
	Balance int64

	// Account settings id at the moment of this transaction processing.
	SettingsID ID

	// Stores ID of Receiver output transaction when this transaction was taken into account.
	// Set by Receiver. 0 if not spent yet.
	// It's not used for transaction Hash calculation.
	SpentBy ID
	// Previous transaction hash of the same Sender.
	PrevHash Hash
	// Hash is an hash of corrent transaction.
	Hash Hash
	// Transfer Sign.
	// If more that one transactions were in the batch only first contains sign of the whole request
	Sign Sign
}

Txn is a single transaction between two accounts. It's a central structure of the project.

See chain package docs for information about how transactions are structured.

type TxnID

type TxnID struct {
	AccID
	ID
}

TxnID is an unique ID for each transaction among all accounts.

func NewTxnID

func NewTxnID(acc AccID, id ID) TxnID

func (TxnID) String

func (t TxnID) String() string

Jump to

Keyboard shortcuts

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