transaction

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2016 License: ISC Imports: 19 Imported by: 0

Documentation

Overview

transaction record handling

contains types for each of the possible transaction records and methods to Pack and Unpack them for storage/transfer.

the transactions form a tree with the following limits 1. registration record (R) is a root and only one in a tree 2. registration transfer records (T) for a single chain trunk 3. bitmark transfer records (B) form single chain branches out from the bitmark transfer 4. there is only one trunk 5. any (T) can have multiple branches 6. new branches can only be added at the apex (T) 7. branches can only grow at their leaf (B)

(R)---(T1)---(T2)---(T3)  <---{ Apex (T3) }
      |  |    |     |  |
      B  B    B     B  B
      |  |    |     |  |
      B  B    B     B  B  <---{ Leaf nodes }

(R)---(T1)---(T2)---(T3)
      |  |    |     |  |\
      B  B    B     B  B B
      |  |    |     |  |  \
      B  B    B     B  B   B  <---{ New branch added at Apex (T3) }
      |             |
      B             B  <---{ New bitmark transfers at any Leaf }

(R)---(T1)---(T2)---(T3)---(T4)  <---{ New Apex (T4) }
      |  |    |     |  |\     |
      B  B    B     B  B B    B  <---{ New branches only allowed from current Apex }
      |  |    |     |  |  \
      B  B    B     B  B   B
      |             |
      B             B

Index

Constants

View Source
const (
	// list of valid algorithms
	Nothing = iota // zero keytype **Just for Testing**
	ED25519 = iota
)

enumeration of supported key algorithms

View Source
const (
	// null marks beginning of list - not used as a record type
	NullTag = TagType(iota)

	// valid record type
	AssetDataTag       = TagType(iota)
	BitmarkIssueTag    = TagType(iota)
	BitmarkTransferTag = TagType(iota)

	// this item must be last
	InvalidTag = TagType(iota)
)

enumerate the possible transaction record types this is encoded a Varint64 at start of "Packed"

View Source
const (
	ExpiredTransaction   = State('E')
	PendingTransaction   = State('P')
	VerifiedTransaction  = State('V')
	ConfirmedTransaction = State('C')
)

possible states for a transaction

View Source
const (
	AssetIndexSize = 64
)

limits

View Source
const (
	LinkSize = block.DigestSize
)

a prefix for the client (for Bitcoin submission)

Variables

This section is empty.

Functions

func AssetIndexFromBytes

func AssetIndexFromBytes(assetIndex *AssetIndex, buffer []byte) error

convert and validate little endian binary byte slice to a assetIndex

func Finalise

func Finalise()

finalise - flush unsaved data

func Initialise

func Initialise()

initialise the transaction data pool

func LinkFromBytes

func LinkFromBytes(link *Link, buffer []byte) error

convert and validate little endian binary byte slice to a link

func LinkFromHexString

func LinkFromHexString(link *Link, hexWithPrefix string) error

convert and validate a little endian hex link string Notes: 1. hex code contains prefix at the beginning 2. this is hex code in same order as hex JSON above

func ReadCounters

func ReadCounters(pending *uint64, verified *uint64)

sanpshot of counts

func RecordName added in v0.1.2

func RecordName(record interface{}) (string, bool)

get the name of a transaction record as a string

Types

type Address

type Address struct {
	AddressInterface
}

base type for addresses

func AddressFromBase58

func AddressFromBase58(addressBase58Encoded string) (*Address, error)

this converts a Base58 encoded string and returns an address

one of the specific address types are returned using the base "AddressInterface" interface type to allow individual methods to be called.

func AddressFromBytes

func AddressFromBytes(addressBytes []byte) (*Address, error)

this converts a byte encoded buffer and returns an address

one of the specific address types are returned using the base "AddressInterface" interface type to allow individual methods to be called.

func (*Address) UnmarshalJSON

func (address *Address) UnmarshalJSON(s []byte) error

convert an address from its Base58 JSON form to binary

this cannot be forwarded by go compiler, since it needs to determine the the resulting interface type from the encoded data

type AddressInterface

type AddressInterface interface {
	KeyType() int
	PublicKeyBytes() []byte
	CheckSignature(message []byte, signature Signature) error
	Bytes() []byte
	String() string
	MarshalJSON() ([]byte, error)
}

type AssetData

type AssetData struct {
	Description string    `json:"description"` // utf-8
	Name        string    `json:"name"`        // utf-8
	Fingerprint string    `json:"fingerprint"` // utf-8
	Registrant  *Address  `json:"registrant"`  // base58
	Signature   Signature `json:"signature"`   // hex
}

the unpacked Asset Data structure

func (*AssetData) AssetIndex

func (assetData *AssetData) AssetIndex() AssetIndex

compute an asset index

func (*AssetData) Pack

func (assetData *AssetData) Pack(address *Address) (Packed, error)

pack AssetData

Pack Varint64(tag) followed by fields in order as struct above with signature last

NOTE: returns the "unsigned" message on signature failure - for

debugging/testing

type AssetIndex

type AssetIndex [AssetIndexSize]byte

the type for an iasset index - same as block digest stored as little endian byte array represented as big endian hex value for print represented as little endian hex text for JSON encoding

func NewAssetIndex

func NewAssetIndex(record []byte) AssetIndex

create an asset index from a byte slice

double SHA2-512 Hash

func (AssetIndex) Bytes

func (assetIndex AssetIndex) Bytes() []byte

convert a binary assetIndex to byte slice

func (AssetIndex) GoString

func (assetIndex AssetIndex) GoString() string

convert a binary assetIndex to big endian hex string for use by the fmt package (for %#v)

func (AssetIndex) MarshalJSON

func (assetIndex AssetIndex) MarshalJSON() ([]byte, error)

convert a binary assetIndex to little endian hex text for JSON

***** possibly re-use MarshalText to save code duplication ***** but would that cost more buffer copying?

func (AssetIndex) MarshalText

func (assetIndex AssetIndex) MarshalText() ([]byte, error)

convert assetIndex to little endian hex text

***** possibly use NewEncoder and byte buffer to save copy

func (AssetIndex) Read

func (asset AssetIndex) Read() (State, Link, bool)

read an Asset from its assetIndex

returns:

state of record - see the const ExpiredTransaction,... above
transaction ID - can be used in link.READ
true if data was found

func (*AssetIndex) Scan

func (assetIndex *AssetIndex) Scan(state fmt.ScanState, verb rune) error

convert a big endian hex text representation to a assetIndex for use by the format package scan routines

func (AssetIndex) String

func (assetIndex AssetIndex) String() string

convert a binary assetIndex to big endian hex string for use by the fmt package (for %s)

func (*AssetIndex) UnmarshalJSON

func (assetIndex *AssetIndex) UnmarshalJSON(s []byte) error

convert a little endian hex string to a assetIndex for conversion from JSON

func (*AssetIndex) UnmarshalText

func (assetIndex *AssetIndex) UnmarshalText(s []byte) error

convert little endian hex text into a assetIndex

type AvailableCursor

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

holds a cursor for fetching confirmed with associated assets

func NewAvailableCursor

func NewAvailableCursor() *AvailableCursor

create a new cursor for FetchAvailable

func (*AvailableCursor) FetchAvailable

func (cursor *AvailableCursor) FetchAvailable(count int) []block.Digest

fetch a list of transaction ids for miner

returns:

list of ids (as digests for merkle tree processing later)

note that an asset txId can be inserted just before an issue txId

if that asset was never seen before

type BitmarkIssue

type BitmarkIssue struct {
	AssetIndex AssetIndex `json:"asset"`     // previous record (or RegistrationTransfer if first record)
	Owner      *Address   `json:"owner"`     // base58: the "destination" owner
	Nonce      uint64     `json:"nonce"`     // to allow for multiple issues at the same time
	Signature  Signature  `json:"signature"` // hex: corresponds to owner in linked record
}

the unpacked BitmarkIssue structure

func (*BitmarkIssue) Pack

func (issue *BitmarkIssue) Pack(address *Address) (Packed, error)

pack BitmarkIssue

Pack Varint64(tag) followed by fields in order as struct above with signature last

NOTE: returns the "unsigned" message on signature failure - for

debugging/testing

type BitmarkTransfer

type BitmarkTransfer struct {
	Link      Link      `json:"link"`      // previous record (or RegistrationTransfer if first record)
	Owner     *Address  `json:"owner"`     // base58: the "destination" owner
	Signature Signature `json:"signature"` // hex: corresponds to owner in linked record
}

the unpacked BitmarkTransfer structure

func (*BitmarkTransfer) Pack

func (transfer *BitmarkTransfer) Pack(address *Address) (Packed, error)

local function to pack BitmarkTransfer

Pack Varint64(tag) followed by fields in order as struct above with signature last

NOTE: returns the "unsigned" message on signature failure - for

debugging/testing

type Decoded

type Decoded struct {
	TxId        Link        `json:"txid"`
	Asset       *AssetIndex `json:"asset"`
	Exists      bool        `json:"exists"`
	State       State       `json:"state"`
	Type        string      `json:"type"`
	Transaction interface{} `json:"transaction"`
	Timestamp   *time.Time  `json:"timestamp"`
}

a decoded transaction type - for JSON conversion

func Decode

func Decode(txIds []Link) []Decoded

decode transaction from list of ids

func FetchPending

func FetchPending() []Decoded

fetch some transactions for client

type ED25519Address

type ED25519Address struct {
	Test      bool
	PublicKey *[ed25519.PublicKeySize]byte
}

for ed25519 signatures

func (*ED25519Address) Bytes

func (address *ED25519Address) Bytes() []byte

byte slice for encoded key

func (*ED25519Address) CheckSignature

func (address *ED25519Address) CheckSignature(message []byte, signature Signature) error

check the signature of a message

func (*ED25519Address) KeyType

func (address *ED25519Address) KeyType() int

key type code (see enumeration above)

func (ED25519Address) MarshalJSON

func (address ED25519Address) MarshalJSON() ([]byte, error)

convert an address to its Base58 JSON form

func (*ED25519Address) PublicKeyBytes

func (address *ED25519Address) PublicKeyBytes() []byte

fetch the public key as byte slice

func (*ED25519Address) String

func (address *ED25519Address) String() string

base58 encoding of encoded key

type IndexCursor

type IndexCursor uint64

type to denote a index in the unpaid, pending or confirmed pools just a 64 bit unsigned integer - big endian byte order (has a Bytes() to fetch the big endian representation

func (IndexCursor) Bytes

func (ic IndexCursor) Bytes() []byte

convert a count to a byte slice (big endian)

func (*IndexCursor) FetchPool

func (cursor *IndexCursor) FetchPool(count int) []Decoded

fetch some transaction ids from pool

returns:

list of ids
cursor set to next start point

func (*IndexCursor) FetchUnpaid

func (cursor *IndexCursor) FetchUnpaid(count int) []UnpaidResult

fetch some transaction ids for payment verification

returns:

list of ids
next start point

func (IndexCursor) MarshalJSON

func (ic IndexCursor) MarshalJSON() ([]byte, error)

convert to JSON

func (IndexCursor) MarshalText

func (ic IndexCursor) MarshalText() ([]byte, error)

convert link to little endian hex text

func (*IndexCursor) NextBytes

func (ic *IndexCursor) NextBytes() []byte

convert a next count to a byte slice (big endian)

func (IndexCursor) String

func (ic IndexCursor) String() string

convert to string

func (*IndexCursor) UnmarshalJSON

func (ic *IndexCursor) UnmarshalJSON(s []byte) error

convert from JSON

func (*IndexCursor) UnmarshalText

func (ic *IndexCursor) UnmarshalText(s []byte) error

convert little endian hex text into a link

type Link block.Digest

the type for a link - same as block digest stored as little endian byte array represented as big endian hex value for print represented as little endian hex text for JSON encoding

func (Link) Bytes

func (link Link) Bytes() []byte

convert a binary link to byte slice

func (Link) GetState

func (link Link) GetState() (State, bool)

state of a transaction

returns:

state of record - see the const ExpiredTransaction,... above
true if data was found

func (Link) GoString

func (link Link) GoString() string

convert a binary link to big endian hex string for use by the fmt package (for %#v)

func (Link) IsOwner

func (link Link) IsOwner(address *Address) bool

see if allowed to transfer ownership

func (Link) MarshalJSON

func (link Link) MarshalJSON() ([]byte, error)

convert a binary link to little endian hex text for JSON

***** possibly re-use MarshalText to save code duplication ***** but would that cost more buffer copying?

func (Link) MarshalText

func (link Link) MarshalText() ([]byte, error)

convert link to little endian hex text

***** possibly use NewEncoder and byte buffer to save copy

func (Link) Read

func (link Link) Read() (State, Packed, bool)

read a transaction

returns:

state of record - see the const ExpiredTransaction,... above
record data as Packed type - just a byte slice
true if data was found

func (*Link) Scan

func (link *Link) Scan(state fmt.ScanState, verb rune) error

convert a big endian hex text representation to a link for use by the format package scan routines

func (Link) SetState

func (link Link) SetState(newState State)

set the state of a transaction

func (Link) String

func (link Link) String() string

convert a binary link to big endian hex string for use by the fmt package (for %s)

func (*Link) UnmarshalJSON

func (link *Link) UnmarshalJSON(s []byte) error

convert a little endian hex string to a link for conversion from JSON

func (*Link) UnmarshalText

func (link *Link) UnmarshalText(s []byte) error

convert little endian hex text into a link

type NothingAddress

type NothingAddress struct {
	Test      bool
	PublicKey *[2]byte
}

just for debugging

func (*NothingAddress) Bytes

func (address *NothingAddress) Bytes() []byte

byte slice for encoded key

func (*NothingAddress) CheckSignature

func (address *NothingAddress) CheckSignature(message []byte, signature Signature) error

check the signature of a message

func (*NothingAddress) KeyType

func (address *NothingAddress) KeyType() int

key type code (see enumeration above)

func (NothingAddress) MarshalJSON

func (address NothingAddress) MarshalJSON() ([]byte, error)

convert an address to its Base58 JSON form

func (*NothingAddress) PublicKeyBytes

func (address *NothingAddress) PublicKeyBytes() []byte

fetch the public key as byte slice

func (*NothingAddress) String

func (address *NothingAddress) String() string

base58 encoding of encoded key

type Ownership added in v0.1.2

type Ownership struct {
	N         uint64 `json:"n,string"`
	TxId      Link   `json:"txid"`
	IssueTxId Link   `json:"issue"`
	AssetTxId Link   `json:"asset"`
}

type to represent an ownership record

func FetchOwnership added in v0.1.2

func FetchOwnership(owner *Address, start uint64, count int) ([]Ownership, error)

fetch a set of ownership records

type Packed

type Packed []byte

packed records are just a byte slice

func (Packed) Exists

func (data Packed) Exists() (Link, bool)

see if a transaction already exists and compute its ID

note this will panic if database inconsistancy is detected

func (record Packed) MakeLink() Link

Create an link for a packed record

reuse the block algorithm

func (Packed) MarshalJSON

func (p Packed) MarshalJSON() ([]byte, error)

convert a packed to its hex JSON form

func (Packed) Type

func (record Packed) Type() TagType

determine the record type code

func (Packed) Unpack

func (record Packed) Unpack() (interface{}, error)

turn a byte slice into a record

must cast result to correct type

e.g.

registration, ok := result.(*transaction.Registration)

or:

switch result.(type) {
case *transaction.Registration:

func (Packed) Write

func (data Packed) Write(link *Link, overwriteAssetIndex bool) error

write a transaction

returns:

whether the values was added (false => already exists)
the ID of the transaction

this enters the transaction as an pending new transaction

type Signature

type Signature []byte

the type for a signature

func (Signature) GoString

func (signature Signature) GoString() string

convert a binary signature to hex string for use by the fmt package (for %#v)

func (Signature) MarshalJSON

func (signature Signature) MarshalJSON() ([]byte, error)

convert a binary signature to hex for unpacking record to JSON

func (Signature) MarshalText

func (signature Signature) MarshalText() ([]byte, error)

convert signature to text

func (*Signature) Scan

func (signature *Signature) Scan(state fmt.ScanState, verb rune) error

convert a text representation to a signature for use by the format package scan routines

func (Signature) String

func (signature Signature) String() string

convert a binary signature to hex string for use by the fmt package (for %s)

func (*Signature) UnmarshalJSON

func (signature *Signature) UnmarshalJSON(s []byte) error

convert an hex string to a signature for conversion from JSON

func (*Signature) UnmarshalText

func (signature *Signature) UnmarshalText(s []byte) error

convert text into a signature

type State

type State byte

type for transaction state

func (State) CanChangeTo

func (state State) CanChangeTo(newState State) bool

func (State) MarshalJSON

func (state State) MarshalJSON() ([]byte, error)

convert a state to text for JSON

func (State) MarshalText

func (state State) MarshalText() ([]byte, error)

convert state to text

Note: Each string _MUST_ start with a unique capital letter so client only need to test firrst character.

func (State) String

func (state State) String() string

type TagType

type TagType uint64

type UnpaidResult

type UnpaidResult struct {
	Link      Link
	Timestamp time.Time
}

type to hold unpaid items

Jump to

Keyboard shortcuts

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