factoid

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2015 License: MIT Imports: 11 Imported by: 0

README

factoid

Package factoid implements the factoid chain, a bitcoin inspired transaction ledger secured by the federated server factom consensus protocol.

Documentation

Index

Constants

View Source
const (
	FACTOID_ADDR     = byte(0)
	ENTRYCREDIT_PKEY = byte(1)
)

Constants for Output.Type

View Source
const (
	FaucetTxidStr = "FaucetTxidForSymulationTesting01"
)
View Source
const (
	GenesisAddress = "FfZgRRHxuzsWkhXcb5Tb16EYuDEkbVCPAk1svfmYxyUXGPoS2X"
)
View Source
const (
	//initail array allocation
	//each call to append will double capacity when len() = cap()
	TxPoolAllocSize = 1000
)

Variables

This section is empty.

Functions

func AddSingleSigToTxMsg

func AddSingleSigToTxMsg(txm *TxMsg, ss *SingleSignature)

func AddressFromPubKey

func AddressFromPubKey(pk *[32]byte, netID byte) string

func EncodeAddress

func EncodeAddress(hashokey Address, netID byte) string

encodeAddress returns a human-readable payment address given a 32 bytes hash or publike-key and netID which encodes the factom network and address type. It is used in both entrycredit and factoid transactions.

func GetBalance

func GetBalance(address string) (bal int64)

GetBalance from GlobalUtxo helper function ToDo: should be depricated on GlobalUtxo redesign

func IsFaucet

func IsFaucet(in *Input) bool

func NewDBEntryFromFBlock

func NewDBEntryFromFBlock(b *FBlock) *notaryapi.DBEntry

func NewOrphanPool

func NewOrphanPool() *orphanpool

create new orphanpool

func NewTxPool

func NewTxPool() *txpool

create new txpool, allocate TxPoolAllocSize

func TxMsgToWire

func TxMsgToWire(txm *TxMsg) (tx *factomwire.MsgTx)

convert from TxMsg to wire format

func VerifyAddressReveal

func VerifyAddressReveal(address Address, reveal AddressReveal) bool

func VerifyInputSig

func VerifyInputSig(in *Input, sig *InputSig, tx *Tx) bool

func VerifyTx

func VerifyTx(tx *Tx) bool

Types

type Address

type Address notaryapi.ByteArray

raw address, either a hash of *Reveal (for factoid tx)

or a raw PublicKey (for entrycredit tx)

func DecodeAddress

func DecodeAddress(addr string) (hashokey Address, netID byte, err error)

DecodeAddress decodes the string encoding of an address and returns the Address and netId

type AddressReveal

type AddressReveal notaryapi.DetachedPublicKey

revealed address is the public key

type ByFBlockIDAccending

type ByFBlockIDAccending []FBlock

------------------------------------------------ FBlock array sorting implementation - accending

func (ByFBlockIDAccending) Len

func (f ByFBlockIDAccending) Len() int

func (ByFBlockIDAccending) Less

func (f ByFBlockIDAccending) Less(i, j int) bool

func (ByFBlockIDAccending) Swap

func (f ByFBlockIDAccending) Swap(i, j int)

type EntryCreditAddress

type EntryCreditAddress AddressReveal

EntryCredit transactions sent directly to publickey

type FBlock

type FBlock struct {
	Header       FBlockHeader
	Transactions []Tx

	//Not Marshalized
	FBHash   *notaryapi.Hash
	Salt     *notaryapi.Hash
	Chain    *FChain
	IsSealed bool
}

Factoid Block - contains list of Tx, which has raw MsgTx plus the Txid

func CreateFBlock

func CreateFBlock(chain *FChain, prev *FBlock, cap uint) (b *FBlock, err error)

func FactoidGenesis

func FactoidGenesis(net factomwire.FactomNet) (genesis *FBlock)

func (*FBlock) AddFBTransaction

func (b *FBlock) AddFBTransaction(t Tx) (err error)

func (*FBlock) MarshalBinary

func (b *FBlock) MarshalBinary() (data []byte, err error)

func (*FBlock) MarshalledSize

func (b *FBlock) MarshalledSize() uint64

func (*FBlock) UnmarshalBinary

func (b *FBlock) UnmarshalBinary(data []byte) (err error)

type FBlockHeader

type FBlockHeader struct {
	Height        uint64
	PrevBlockHash *notaryapi.Hash
	TimeStamp     int64
	TxCount       uint32
}

Factoid Block header

func NewFBlockHeader

func NewFBlockHeader(blockId uint64, prevHash *notaryapi.Hash, merkle *notaryapi.Hash) *FBlockHeader

func (*FBlockHeader) MarshalBinary

func (b *FBlockHeader) MarshalBinary() (data []byte, err error)

func (*FBlockHeader) MarshalledSize

func (b *FBlockHeader) MarshalledSize() uint64

func (*FBlockHeader) UnmarshalBinary

func (b *FBlockHeader) UnmarshalBinary(data []byte) (err error)

type FChain

type FChain struct {
	ChainID      *notaryapi.Hash
	Name         [][]byte
	Blocks       []*FBlock
	CurrentBlock *FBlock
	BlockMutex   sync.Mutex
	NextBlockID  uint64
}

func (*FChain) MarshalBinary

func (b *FChain) MarshalBinary() (data []byte, err error)

func (*FChain) MarshalledSize

func (b *FChain) MarshalledSize() uint64

func (*FChain) UnmarshalBinary

func (b *FChain) UnmarshalBinary(data []byte) (err error)

type FactoidPool

type FactoidPool struct {
	TxProcessor
	sync.RWMutex
	// contains filtered or unexported fields
}

txMemPool is used as a source of transactions that need to be mined into blocks and relayed to other peers. It is safe for concurrent access from multiple peers.

factoidpool impliments TxProcessor for generic mempool processing

func NewFactoidPool

func NewFactoidPool() *FactoidPool

newTxMemPool returns a new memory pool for validating and storing standalone transactions until they are mined into a block.

func (*FactoidPool) AddGenesisBlock

func (fp *FactoidPool) AddGenesisBlock()

func (*FactoidPool) AddToMemPool

func (fp *FactoidPool) AddToMemPool() (verified []*notaryapi.HashF)

add transaction to memorypool after passing verification of signature and utxo assume the transaction is already set to factoidpool.context via call to SetContext

func (*FactoidPool) Confirm

func (fp *FactoidPool) Confirm(fm *factomwire.MsgConfirmation) (ok bool, confirmed []*notaryapi.HashF)

Confirm is called when receivedd a confirmation msg from federatd server should only be called after already received the Tx ToDo: deal with confirms that come in diff order than in pool,

may need to store doubel spends, they may become valid

func (*FactoidPool) GetTxContext

func (fp *FactoidPool) GetTxContext() *Tx

func (*FactoidPool) SetContext

func (fp *FactoidPool) SetContext(tx *factomwire.MsgTx)

*** TxProcessor implimentaion ***// set context to tx, this context will be used by default when by Verify and AddToMemPool see factomd.TxMempool

func (*FactoidPool) Utxo

func (fp *FactoidPool) Utxo() *Utxo

func (*FactoidPool) Verify

func (fp *FactoidPool) Verify() (ret bool)

Verify is designed to be called by external packages without them needing to know the specific Tx foramt

type Input

type Input struct {
	Txid       Txid
	Index      uint32
	RevealAddr AddressReveal //notaryapi.ByteArray
}

Input is the UTXO being spent

Txid defines the transaction that contains Output being spent
Index is Output number
RevealAddr is the "reveal" for the Output.ToAddr "commit"
		it contains the public-key(s) corresponding to Signatures

func NewFaucetIn

func NewFaucetIn() *Input

use time as nonce - shouls always work

func NewFaucetInput

func NewFaucetInput(nonce uint32) *Input

Create Input with faucet TXID. This input will not be checked against Utxo and will always be valid. Nonce is used to make resulting Transactions unique only need to update nonce when rest to Tx is same a previous one. /ToDo: remove before production

func NewInput

func NewInput(id *Txid, index uint32, reveal AddressReveal) *Input

NewInput returns a new factoid transaction input with the provided Txid, index, and revealed address

func (*Input) MarshalBinary

func (i *Input) MarshalBinary() (data []byte, err error)

func (*Input) MarshalledSize

func (i *Input) MarshalledSize() uint64

func (*Input) String

func (o *Input) String() string

func (*Input) UnmarshalBinary

func (i *Input) UnmarshalBinary(data []byte) (err error)

type InputSig

type InputSig struct {
	Hint rune
	Sigs []SingleSignature
}

all sigs needed for input

Hint is used to help match sig to multi input tx
	signatures can then be reordered correctly, so can be
	vefified w/o hint. this allows signatures to sent and
	attached to tx in any order

func (*InputSig) AddSig

func (ins *InputSig) AddSig(ss SingleSignature)

AddSig to append singlesignature to InputSig

func (*InputSig) MarshalBinary

func (is *InputSig) MarshalBinary() (data []byte, err error)

func (*InputSig) MarshalledSize

func (is *InputSig) MarshalledSize() uint64

func (*InputSig) UnmarshalBinary

func (is *InputSig) UnmarshalBinary(data []byte) (err error)

type MultisigReveal

type MultisigReveal struct {
	NumRequired uint8
	Addresses   []AddressReveal
}

multisig reveal structure that hashes into raw Address

type Output

type Output struct {
	Type   byte
	Amount int64
	ToAddr Address
}

Output defines a receiver of the Input

Output.Type
	FACTOID_ADDR
	ENTRYCREDIT_PKEY

Amount is amount of transfer in "Snow"
ToAddr is a hash of struct, with public-keys(s)
	for Type = ENTRYCREDIT_PKEY , ToAddr is public-key

func NewOutput

func NewOutput(ty byte, amount int64, to Address) *Output

NewOutput returns a new bitcoin transaction output with the provided transaction value and public key script.

func OutputsTx

func OutputsTx(tx *Tx) []Output

func (*Output) MarshalBinary

func (o *Output) MarshalBinary() (data []byte, err error)

func (*Output) MarshalledSize

func (o *Output) MarshalledSize() uint64

func (*Output) String

func (o *Output) String() string

func (*Output) ToAddressString

func (o *Output) ToAddressString() string

func (*Output) UnmarshalBinary

func (o *Output) UnmarshalBinary(data []byte) (err error)

type SingleSignature

type SingleSignature struct {
	Hint rune
	Sig  notaryapi.DetachedSignature
}

single signature of tx,

Hint is not signed! is used to help match sig to address in multisig input.

func NewSingleSignature

func NewSingleSignature(insig *notaryapi.DetachedSignature) (ss *SingleSignature)

func SingleSigFromByte

func SingleSigFromByte(sb []byte) (sig SingleSignature)

func (*SingleSignature) MarshalBinary

func (s *SingleSignature) MarshalBinary() (data []byte, err error)

func (*SingleSignature) MarshalledSize

func (s *SingleSignature) MarshalledSize() uint64

func (*SingleSignature) String

func (s *SingleSignature) String() string

func (*SingleSignature) UnmarshalBinary

func (s *SingleSignature) UnmarshalBinary(data []byte) (err error)

type Tx

type Tx struct {
	Txm *TxMsg
	// contains filtered or unexported fields
}

Tx is the TxMsg and a chache of its Txid

func NewTx

func NewTx(txm *TxMsg) *Tx

NewTx returns a new instance of a factoid transaction given an underlying TxMsg

func (*Tx) Digest

func (tx *Tx) Digest() []byte

func (*Tx) Id

func (tx *Tx) Id() *Txid

type TxData

type TxData struct {
	Inputs   []Input
	Outputs  []Output
	LockTime uint32
}

TxData is the core of the transaction, it generates the TXID TxData is signed by each input

LockTime is intened as used in bitcoin

func NewTxData

func NewTxData() *TxData

create new TxData

func (*TxData) AddInput

func (td *TxData) AddInput(in Input)

AddInput adds a transaction input.

func (*TxData) AddOutput

func (td *TxData) AddOutput(out Output)

AddOutput adds a transaction output.

func (*TxData) MarshalBinary

func (tx *TxData) MarshalBinary() (data []byte, err error)

func (*TxData) MarshalledSize

func (tx *TxData) MarshalledSize() uint64

func (*TxData) Txid

func (td *TxData) Txid(bin *[]byte) (txid *Txid)

return transaction id of transacion

func (*TxData) UnmarshalBinary

func (tx *TxData) UnmarshalBinary(data []byte) (err error)

type TxMsg

type TxMsg struct {
	//Version int32
	TxData *TxData
	Sigs   []InputSig
}

TxMsg is the signed and versioned Factoid transaction message

Sigs is at least 1 signature per Input

func NewTxFromInputToAddr

func NewTxFromInputToAddr(in *Input, snowAmount int64, to Address) (txm *TxMsg)

func NewTxFromOutputToAddr

func NewTxFromOutputToAddr(txid *Txid, outs []Output, outnum uint32, from AddressReveal, to Address) (txm *TxMsg)

func NewTxMsg

func NewTxMsg(td *TxData) *TxMsg

crate TxMsg from TxData

func TxMsgFromWire

func TxMsgFromWire(tx *factomwire.MsgTx) (txm *TxMsg)

convert from wire format to TxMsg

func (*TxMsg) AddInputSig

func (tm *TxMsg) AddInputSig(is InputSig)

AddInputSig adds a signature to transaction.

func (*TxMsg) MarshalBinary

func (txm *TxMsg) MarshalBinary() (data []byte, err error)

func (*TxMsg) MarshalledSize

func (txm *TxMsg) MarshalledSize() uint64

func (*TxMsg) Txid

func (txm *TxMsg) Txid(bin *[]byte) *Txid

return transaction id of transacion

func (*TxMsg) UnmarshalBinary

func (txm *TxMsg) UnmarshalBinary(data []byte) (err error)

type TxOutSpent

type TxOutSpent struct {
	Outs  []Output
	Spent TxSpentList
}

type TxProcessor

type TxProcessor interface {
	SetContext(*factomwire.MsgTx)
	Verify() bool
	//Broadcast()
	AddToMemPool() []*notaryapi.HashF
	Confirm(*factomwire.MsgConfirmation) (bool, []*notaryapi.HashF)
}

ToDo: TxProcessor was copied from factomd.txmempool due to import cycle issues. fix this

TxProcessor is an interface that abstracts methods needed to process a TxMessage SetContext(*TxMessage) will store to concrete TxMessage in the concrete TxProcessor object

type TxSpentList

type TxSpentList []bool

ToDo: use bits if faster , or if keeping full utxo in memory. should really do memory mapped files//

TxSpentList is a vector of bool indicators of:

if $Txids[tx.Input[i].Txid].Output[tx.Input[i].Index] have been spent

Output type ENTRYCREDIT_PKEY outputs are always flagged as spent

type Txid

type Txid notaryapi.HashF
var (
	FaucetTxid *Txid
)

func NewTxidFromString

func NewTxidFromString(stxid string) (txid *Txid)

func (*Txid) FromString

func (txid *Txid) FromString(stxid string) *Txid

func (*Txid) String

func (txid *Txid) String() string

type Utxo

type Utxo struct {
	Txspent map[Txid]TxOutSpent
	//BalanceByAddress is used to store current address balance
	// used during testing of factoid, while full wallet in developent
	//ToDo: refactor
	BalanceByAddress map[string]int64
}

Unspent TransaXtion Outputs is implimented as a hashtable from Txid to bool array TxSpentList

var GlobalUtxo Utxo

GlobalUtxo will store utxo for all blocks temp use global var, to be called from "restapi" ToDo: redesign

func GetGlobUtxo

func GetGlobUtxo() *Utxo

func NewUtxo

func NewUtxo() Utxo

Utxo constructor

func (*Utxo) AddTx

func (u *Utxo) AddTx(t *Tx)

add transaction to Utxo used when tx passed all verifications ToDo: maybe support Udue (command pattern?)

func (*Utxo) AddUtxo

func (u *Utxo) AddUtxo(id *Txid, outs []Output)

add all outputs for txid to UTXO

func (*Utxo) AddVerifiedTxList

func (u *Utxo) AddVerifiedTxList(tx []Tx)

Meant for adding verified blocks to Utxo

func (*Utxo) AddressBalance

func (u *Utxo) AddressBalance(addr string) int64

func (*Utxo) InputsKnown

func (u *Utxo) InputsKnown(in []Input) (bool, []*Txid)

true if input parents are known

func (*Utxo) IsValid

func (u *Utxo) IsValid(in []Input) bool

IsValid checks Inputs and returns true if all inputs are in current Utxo

func (*Utxo) Spend

func (u *Utxo) Spend(in []Input)

Spend will mark Input as Spent in Utxo

Jump to

Keyboard shortcuts

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