Documentation ¶
Overview ¶
Package factom provides data types corresponding to some of the Factom blockchain's data structures, as well as methods on those types for securely querying the data from factomd and factom-walletd's APIs.
In this case, secure means that all of the cryptographic hashes related to a factom data structure are verified during BinaryUnmarshaling.
All of the Factom data structure types in this package have Get, IsPopulated, MarshalBinary, and UnmarshalBinary methods. All Get functions populate the object they are called on, and use a factomd raw data API to pass to UnmarshalBinary, which also performs all applicable cryptographic validation.
Methods that accept a *Client, like those that start with Get, will make calls to the factomd or factom-walletd API queries to populate the data in the variable on which it is called. The returned error can be checked to see if it is a jsonrpc2.Error type, indicating that the networking calls were successful, but that there is some error returned by the RPC method.
IsPopulated methods return whether the data in the variable has been populated by a successful call to Get.
The DBlock, EBlock and Entry types allow for exploring the Factom blockchain.
The Bytes and Bytes32 types implement the encoding.TextMarshaler and encoding.TextUnmarshaler interfaces and are used by other types when JSON marshaling and unmarshaling to and from hex strings is required.
Bytes32 is an array used for ChainIDs, KeyMRs, and other 32 byte hashes.
The Address interfaces and types allow for working with the four Factom address types.
The IDKey interfaces and types allow for working with the id/sk key pairs for server identities.
The Identity type provides a way to retrieve the ID1Key from an established Identity Chain.
Currently this package supports creating new chains and entries using both the factom-walletd "compose" methods, and by locally generating the commit and reveal data, if the private entry credit key is available locally. See Entry.Create and Entry.ComposeCreate.
This package does not yet support Factoid transactions, nor does it support the binary data structures for Admin Blocks, Entry Credit Blocks, or Factoid Blocks.
Index ¶
- Constants
- Variables
- func EntryCost(size int, newChain bool) (uint8, error)
- func ValidIdentityChainID(chainID Bytes) bool
- func ValidIdentityNameIDs(nameIDs []Bytes) bool
- type AddressAmount
- type Bytes
- type Bytes32
- func ABlockChainID() Bytes32
- func ComputeChainID(nameIDs []Bytes) Bytes32
- func ComputeDBlockBodyMR(elements [][]byte) (Bytes32, error)
- func ComputeDBlockHeaderHash(data []byte) Bytes32
- func ComputeEBlockBodyMR(elements [][]byte) (Bytes32, error)
- func ComputeEBlockHeaderHash(data []byte) Bytes32
- func ComputeEntryHash(data []byte) Bytes32
- func ComputeFBlockBodyMR(elements [][]byte) (Bytes32, error)
- func ComputeFBlockKeyMR(elements [][]byte) (Bytes32, error)
- func ComputeFullHash(data []byte) Bytes32
- func ComputeKeyMR(headerHash, bodyMR *Bytes32) Bytes32
- func ECBlockChainID() Bytes32
- func FBlockChainID() Bytes32
- func GenerateCommit(es EsAddress, entrydata []byte, hash *Bytes32, newChain bool) ([]byte, Bytes32)
- func NewBytes32(s32 string) Bytes32
- type Client
- func (c *Client) Commit(ctx context.Context, commit []byte) error
- func (c *Client) FactomdRequest(ctx context.Context, method string, params, result interface{}) error
- func (c *Client) GetPrivateAddresses(ctx context.Context) ([]FsAddress, []EsAddress, error)
- func (c *Client) Reveal(ctx context.Context, reveal []byte) error
- func (c *Client) SavePrivateAddresses(ctx context.Context, adrs ...string) error
- func (c *Client) WalletdRequest(ctx context.Context, method string, params, result interface{}) error
- type DBlock
- func (db *DBlock) ClearMarshalBinaryCache()
- func (db DBlock) EBlock(chainID Bytes32) *EBlock
- func (db *DBlock) Get(ctx context.Context, c *Client) (err error)
- func (db DBlock) IsPopulated() bool
- func (db DBlock) MarshalBinary() ([]byte, error)
- func (db DBlock) MarshalBinaryLen() int
- func (db *DBlock) UnmarshalBinary(data []byte) error
- type EBlock
- func (eb *EBlock) ClearMarshalBinaryCache()
- func (eb *EBlock) Get(ctx context.Context, c *Client) error
- func (eb *EBlock) GetChainHead(ctx context.Context, c *Client) (bool, error)
- func (eb *EBlock) GetEntries(ctx context.Context, c *Client) error
- func (eb *EBlock) GetFirst(ctx context.Context, c *Client) error
- func (eb EBlock) GetPrevAll(ctx context.Context, c *Client) ([]EBlock, error)
- func (eb EBlock) GetPrevBackTo(ctx context.Context, c *Client, keyMR *Bytes32) ([]EBlock, error)
- func (eb EBlock) GetPrevN(ctx context.Context, c *Client, n uint32) ([]EBlock, error)
- func (eb EBlock) IsFirst() bool
- func (eb EBlock) IsPopulated() bool
- func (eb EBlock) MarshalBinary() ([]byte, error)
- func (eb EBlock) MarshalBinaryLen() int
- func (eb EBlock) Prev() EBlock
- func (eb *EBlock) SetTimestamp(ts time.Time)
- func (eb *EBlock) UnmarshalBinary(data []byte) error
- type ECAddress
- func (adr ECAddress) GetBalance(ctx context.Context, c *Client) (uint64, error)
- func (adr ECAddress) GetEsAddress(ctx context.Context, c *Client) (EsAddress, error)
- func (adr ECAddress) MarshalText() ([]byte, error)
- func (ECAddress) PrefixBytes() Bytes
- func (ECAddress) PrefixString() string
- func (adr ECAddress) PublicKey() ed25519.PublicKey
- func (adr ECAddress) Remove(ctx context.Context, c *Client) error
- func (adr *ECAddress) Set(adrStr string) error
- func (adr ECAddress) String() string
- func (adr *ECAddress) UnmarshalText(text []byte) error
- type Entry
- func (e *Entry) ClearMarshalBinaryCache()
- func (e *Entry) Compose(es EsAddress) (commit []byte, reveal []byte, txID Bytes32, err error)
- func (e *Entry) ComposeCreate(ctx context.Context, c *Client, es EsAddress) (Bytes32, error)
- func (e Entry) Cost() (uint8, error)
- func (e *Entry) Create(ctx context.Context, c *Client, ec ECAddress) (Bytes32, error)
- func (e *Entry) Get(ctx context.Context, c *Client) error
- func (e Entry) IsPopulated() bool
- func (e Entry) MarshalBinary() ([]byte, error)
- func (e Entry) MarshalBinaryLen() int
- func (e *Entry) UnmarshalBinary(data []byte) error
- type EsAddress
- func (adr EsAddress) ECAddress() (ec ECAddress)
- func (adr EsAddress) GetBalance(ctx context.Context, c *Client) (uint64, error)
- func (adr EsAddress) MarshalText() ([]byte, error)
- func (EsAddress) PrefixBytes() Bytes
- func (EsAddress) PrefixString() string
- func (adr EsAddress) PrivateKey() ed25519.PrivateKey
- func (adr EsAddress) PublicKey() ed25519.PublicKey
- func (adr EsAddress) Remove(ctx context.Context, c *Client) error
- func (adr EsAddress) Save(ctx context.Context, c *Client) error
- func (adr *EsAddress) Set(adrStr string) error
- func (adr EsAddress) String() string
- func (adr *EsAddress) UnmarshalText(text []byte) error
- type FAAddress
- func (adr FAAddress) GetBalance(ctx context.Context, c *Client) (uint64, error)
- func (adr FAAddress) GetFsAddress(ctx context.Context, c *Client) (FsAddress, error)
- func (adr FAAddress) MarshalText() ([]byte, error)
- func (FAAddress) PrefixBytes() Bytes
- func (FAAddress) PrefixString() string
- func (adr FAAddress) Remove(ctx context.Context, c *Client) error
- func (adr *FAAddress) Set(adrStr string) error
- func (adr FAAddress) String() string
- func (adr *FAAddress) UnmarshalText(text []byte) error
- type FBlock
- func (fb *FBlock) ClearMarshalBinaryCache()
- func (fb FBlock) ComputeFullHash() (Bytes32, error)
- func (fb *FBlock) Get(ctx context.Context, c *Client) (err error)
- func (fb FBlock) IsPopulated() bool
- func (fb *FBlock) MarshalBinary() ([]byte, error)
- func (fb *FBlock) UnmarshalBinary(data []byte) (err error)
- type FsAddress
- func (adr FsAddress) FAAddress() FAAddress
- func (adr FsAddress) GetBalance(ctx context.Context, c *Client) (uint64, error)
- func (adr FsAddress) MarshalText() ([]byte, error)
- func (FsAddress) PrefixBytes() Bytes
- func (FsAddress) PrefixString() string
- func (adr FsAddress) PrivateKey() ed25519.PrivateKey
- func (adr FsAddress) PublicKey() ed25519.PublicKey
- func (adr FsAddress) RCD() RCD
- func (adr FsAddress) Remove(ctx context.Context, c *Client) error
- func (adr FsAddress) Save(ctx context.Context, c *Client) error
- func (adr *FsAddress) Set(adrStr string) error
- func (adr FsAddress) Sign(msg []byte) []byte
- func (adr FsAddress) String() string
- func (adr *FsAddress) UnmarshalText(text []byte) error
- type Heights
- type ID1Key
- func (key ID1Key) MarshalText() ([]byte, error)
- func (key ID1Key) Payload() [sha256.Size]byte
- func (ID1Key) PrefixBytes() []byte
- func (ID1Key) PrefixString() string
- func (key *ID1Key) Set(keyStr string) error
- func (key ID1Key) String() string
- func (ID1Key) Type() string
- func (key *ID1Key) UnmarshalText(text []byte) error
- type ID2Key
- func (key ID2Key) MarshalText() ([]byte, error)
- func (key ID2Key) Payload() [sha256.Size]byte
- func (ID2Key) PrefixBytes() []byte
- func (ID2Key) PrefixString() string
- func (key *ID2Key) Set(keyStr string) error
- func (key ID2Key) String() string
- func (ID2Key) Type() string
- func (key *ID2Key) UnmarshalText(text []byte) error
- type ID3Key
- func (key ID3Key) MarshalText() ([]byte, error)
- func (key ID3Key) Payload() [sha256.Size]byte
- func (ID3Key) PrefixBytes() []byte
- func (ID3Key) PrefixString() string
- func (key *ID3Key) Set(keyStr string) error
- func (key ID3Key) String() string
- func (ID3Key) Type() string
- func (key *ID3Key) UnmarshalText(text []byte) error
- type ID4Key
- func (key ID4Key) MarshalText() ([]byte, error)
- func (key ID4Key) Payload() [sha256.Size]byte
- func (ID4Key) PrefixBytes() []byte
- func (ID4Key) PrefixString() string
- func (key *ID4Key) Set(keyStr string) error
- func (key ID4Key) String() string
- func (ID4Key) Type() string
- func (key *ID4Key) UnmarshalText(text []byte) error
- type Identity
- type NetworkID
- type PendingEntries
- type RCD
- func (rcd RCD) FAAddress() FAAddress
- func (rcd RCD) Hash() Bytes32
- func (rcd RCD) SignatureBlockSize() int
- func (rcd RCD) String() string
- func (rcd RCD) Type() RCDType
- func (rcd *RCD) UnmarshalBinary(data []byte) error
- func (rcd RCD) Validate(sig, msg []byte, whitelist ...RCDType) error
- func (rcd RCD) ValidateType01(sig, msg []byte) error
- type RCDSignature
- type RCDSigner
- type RCDType
- type SK1Key
- func (key SK1Key) ID1Key() ID1Key
- func (key SK1Key) MarshalText() ([]byte, error)
- func (key SK1Key) Payload() [sha256.Size]byte
- func (SK1Key) PrefixBytes() []byte
- func (SK1Key) PrefixString() string
- func (key SK1Key) PrivateKey() ed25519.PrivateKey
- func (key SK1Key) PublicKey() ed25519.PublicKey
- func (key SK1Key) RCD() RCD
- func (key *SK1Key) Set(keyStr string) error
- func (key SK1Key) Sign(msg []byte) []byte
- func (key SK1Key) String() string
- func (SK1Key) Type() string
- func (key *SK1Key) UnmarshalText(text []byte) error
- type SK2Key
- func (key SK2Key) ID2Key() ID2Key
- func (key SK2Key) MarshalText() ([]byte, error)
- func (key SK2Key) Payload() [sha256.Size]byte
- func (SK2Key) PrefixBytes() []byte
- func (SK2Key) PrefixString() string
- func (key SK2Key) PrivateKey() ed25519.PrivateKey
- func (key SK2Key) PublicKey() ed25519.PublicKey
- func (key SK2Key) RCD() RCD
- func (key *SK2Key) Set(keyStr string) error
- func (key SK2Key) Sign(msg []byte) []byte
- func (key SK2Key) String() string
- func (SK2Key) Type() string
- func (key *SK2Key) UnmarshalText(text []byte) error
- type SK3Key
- func (key SK3Key) ID3Key() ID3Key
- func (key SK3Key) MarshalText() ([]byte, error)
- func (key SK3Key) Payload() [sha256.Size]byte
- func (SK3Key) PrefixBytes() []byte
- func (SK3Key) PrefixString() string
- func (key SK3Key) PrivateKey() ed25519.PrivateKey
- func (key SK3Key) PublicKey() ed25519.PublicKey
- func (key SK3Key) RCD() RCD
- func (key *SK3Key) Set(keyStr string) error
- func (key SK3Key) Sign(msg []byte) []byte
- func (key SK3Key) String() string
- func (SK3Key) Type() string
- func (key *SK3Key) UnmarshalText(text []byte) error
- type SK4Key
- func (key SK4Key) ID4Key() ID4Key
- func (key SK4Key) MarshalText() ([]byte, error)
- func (key SK4Key) Payload() [sha256.Size]byte
- func (SK4Key) PrefixBytes() []byte
- func (SK4Key) PrefixString() string
- func (key SK4Key) PrivateKey() ed25519.PrivateKey
- func (key SK4Key) PublicKey() ed25519.PublicKey
- func (key SK4Key) RCD() RCD
- func (key *SK4Key) Set(keyStr string) error
- func (key SK4Key) Sign(msg []byte) []byte
- func (key SK4Key) String() string
- func (SK4Key) Type() string
- func (key *SK4Key) UnmarshalText(text []byte) error
- type Transaction
- func (tx *Transaction) ClearMarshalBinaryCache()
- func (tx Transaction) IsPopulated() bool
- func (tx Transaction) MarshalBinary() ([]byte, error)
- func (tx Transaction) MarshalBinaryLedger() ([]byte, error)
- func (tx Transaction) MarshalBinaryLen() int
- func (tx *Transaction) Sign(signingSet ...RCDSigner) ([]byte, error)
- func (tx *Transaction) UnmarshalBinary(data []byte) error
Constants ¶
const ( FactomdDefault = "http://localhost:8088/v2" WalletdDefault = "http://localhost:8089/v2" )
Defaults for the factomd and factom-walletd endpoints.
const ( EntryCommitSize = 1 + 6 + 32 + 1 + 32 + 64 // sig ChainCommitSize = EntryCommitSize + 32 + 32 // commit weld )
const ( // RCDType01 is the magic number identifying the RCD type that requires // an ed25519 signature from the given public key. RCDType01 RCDType = 0x01 // RCDType01Size is the total size of the RCD. RCDType01Size = 1 + ed25519.PublicKeySize // RCDType01SigSize is the size of the expected ed25519 signature. RCDType01SigSize = ed25519.SignatureSize )
const ( // TransactionVersion is the magic number Version byte in all // Transactions. TransactionVersion byte = 0x02 // TransactionHeaderSize is the size of a Binary Transaction Header. TransactionHeaderSize = 1 + 6 + 1 + 1 + 1 // EC output count TransactionMinTotalSize = TransactionHeaderSize + 32 + 1 + 32 + 1 + 33 + 32 // RCD01 and Signature )
const DBlockEBlockSize = 32 + 32 // KeyMR
DBlockEBlockSize is the exact length of an EBlock within a DBlock.
const DBlockHeaderSize = 1 + 4 + 32 + 32 + 32 + 4 + 4 + 4 // EBlock Count
DBlockHeaderSize is the exact length of a DBlock header.
const DBlockMaxBodySize = math.MaxUint32 * DBlockEBlockSize
DBlockMaxBodySize is the maximum length of the body of a DBlock, which is determined by the largest EBlock count that can be stored in 4 bytes.
const DBlockMaxTotalSize = DBlockHeaderSize + DBlockMaxBodySize
DBlockMaxTotalSize is the maximum length of a DBlock.
const DBlockMinBodySize = DBlockEBlockSize + DBlockEBlockSize + DBlockEBlockSize // FCT Block
DBlockMinBodySize is the minimum length of the body of a DBlock, which must include at least an Admin Block, EC Block, and FCT Block.
const DBlockMinTotalSize = DBlockHeaderSize + DBlockMinBodySize
DBlockMinTotalSize is the minumum total length of a DBlock.
const EBlockHeaderSize = 32 + 32 + 32 + 32 + 4 + 4 + 4 // [Entry Count (uint32 BE)]
EBlockHeaderSize is the exact length of an EBlock header.
const EBlockMaxBodySize = math.MaxUint32 * EBlockObjectSize
EBlockMaxBodySize is the maximum length of the body of an EBlock, which is determined by the largest ObjectCount that can be stored in 4 bytes.
const EBlockMaxTotalSize = EBlockHeaderSize + EBlockMaxBodySize
EBlockMaxTotalSize is the maximum total length of an EBlock.
const EBlockMinBodySize = EBlockObjectSize * 2
EBlockMinBodySize is the minimum length of the body of an EBlock, which must include at least on Entry hash and one minute marker.
const EBlockMinTotalSize = EBlockHeaderSize + EBlockMinBodySize
EBlockMinTotalSize is the minimum total length of an EBlock.
const EBlockObjectSize = 32
EBlockObjectSize is the length of an EBlock body object, which may be an Entry hash or minute marker.
const EntryHeaderSize = 1 + 32 + 2 // total len
EntryHeaderSize is the exact length of an Entry header.
const EntryMaxDataSize = 10240
EntryMaxDataSize is the maximum data length of an Entry.
const EntryMaxTotalSize = EntryMaxDataSize + EntryHeaderSize
EntryMaxTotalSize is the maximum total encoded length of an Entry.
const ( // FBlockHeaderMinSize is the minimum expected FBlock Header Size. FBlockHeaderMinSize = 32 + 32 + 32 + 32 + 8 + 4 + 1 + 0 + 4 + 4 // Body Size )
const ( // FBlockMinuteMarker is the byte used to indicate the end of a minute // in the FBlock. FBlockMinuteMarker = 0x00 )
const NewChainCost = 10
NewChainCost is the fixed added cost of creating a new chain.
Variables ¶
var ( DBlockDuration = 10 * time.Minute MinuteDuration = DBlockDuration / 10 )
DBlockDuration is the duration of a complete DBlock. This affects the duration of a "Minute" and should be adjusted if this package is used against a Factom local network that uses a shorter block time.
This affects the parsing and assigning of Timestamps on Transactions in FBlocks and Entries in EBlocks.
Functions ¶
func EntryCost ¶
EntryCost returns the required Entry Credit cost for an entry with encoded length equal to size. An error is returned if size exceeds 10275.
Set newChain to true to add the NewChainCost.
func ValidIdentityChainID ¶
ValidIdentityChainID returns true if the chainID matches the pattern for an Identity Chain ID.
The Identity Chain specification can be found here: https://github.com/FactomProject/FactomDocs/blob/master/Identity.md#factom-identity-chain-creation
func ValidIdentityNameIDs ¶
ValidIdentityNameIDs returns true if the nameIDs match the pattern for a valid Identity Chain. The nameIDs for a chain are the ExtIDs of the first entry in the chain.
The Identity Chain specification can be found here: https://github.com/FactomProject/FactomDocs/blob/master/Identity.md#factom-identity-chain-creation
Types ¶
type AddressAmount ¶
AddressAmount relates a 32 byte Address payload and an Amount.
Bytes are used for the Address for improved unmarshaling efficiency of Transactions.
func (AddressAmount) AddressBytes32 ¶
func (adr AddressAmount) AddressBytes32() Bytes32
AddressBytes32 converts the Address to Bytes32.
func (AddressAmount) ECAddress ¶
func (adr AddressAmount) ECAddress() ECAddress
ECAddress converts the Address to an ECAddress.
func (AddressAmount) FAAddress ¶
func (adr AddressAmount) FAAddress() FAAddress
FAAddress converts the Address to an FAAddress.
type Bytes ¶
type Bytes []byte
Bytes implements encoding.TextMarshaler and encoding.TextUnmarshaler to encode and decode hex strings, such as an Entry's ExtIDs or Content.
func (Bytes) MarshalText ¶
MarshalText encodes b as a hex string. It never returns an error.
func (*Bytes) UnmarshalText ¶
UnmarshalText decodes a hex string into b.
type Bytes32 ¶
type Bytes32 [32]byte
Bytes32 implements encoding.TextMarshaler and encoding.TextUnmarshaler to encode and decode hex strings with exactly 32 bytes of data, such as ChainIDs and KeyMRs.
func ABlockChainID ¶
func ABlockChainID() Bytes32
ABlockChainID returns the ChainID of the Admin Block Chain, 0x00..0a.
func ComputeChainID ¶
ComputeChainID returns the chain ID for a set of NameIDs.
func ComputeDBlockBodyMR ¶
ComputeDBlockBodyMR returns the merkle root of the tree created with elements as leaves, where the leaves are hashed.
func ComputeDBlockHeaderHash ¶
ComputeDBlockHeaderHash returns sha256(data[:DBlockHeaderSize]).
func ComputeEBlockBodyMR ¶
ComputeEBlockBodyMR returns the merkle root of the tree created with elements as leaves, where the leaves are not hashed.
func ComputeEBlockHeaderHash ¶
ComputeEBlockHeaderHash returns sha256(data[:EBlockHeaderSize]).
func ComputeEntryHash ¶
ComputeEntryHash returns the Entry hash of data. Entry's are hashed via: sha256(sha512(data) + data).
func ComputeFBlockBodyMR ¶
ComputeFBlockBodyMR returns the merkle root of the tree created with elements as leaves, where the leaves are hashed.
func ComputeFBlockKeyMR ¶
ComputeFBlockKeyMR returns the Key Merkle root of the FBlock.
func ComputeFullHash ¶
ComputeFullHash returns sha256(data).
func ComputeKeyMR ¶
ComputeKeyMR returns sha256(headerHash|bodyMR).
func ECBlockChainID ¶
func ECBlockChainID() Bytes32
ECBlockChainID returns the ChainID of the Entry Credit Block Chain, 0x00..0c.
func FBlockChainID ¶
func FBlockChainID() Bytes32
FBlockChainID returns the ChainID of the Factoid Block Chain, 0x00..0f.
func GenerateCommit ¶
GenerateCommit generates a commit message signed by es for the given entrydata and hash.
The entrydata must be the valid raw data encoding of an Entry, which can be obtained using Entry.MarshalBinary.
The hash must be the valid Entry Hash, which is anything that Entry.UnmarshalBinary can parse without error and can be obtained using ComputeEntryHash.
If newChain is true, then the commit will be a new Chain commit. The ChainID will be pulled from the entrydata.
If successful, the commit and Entry Transaction ID will be returned.
txID == sha256(commit[:len(commit)-96])
If either entrydata or hash is not valid, the return values will be invalid and panics may occur. It is up to the caller to ensure that the entrydata and hash are valid.
This allows the caller to manage the memory associated with the entrydata and hash, rather than having to regenerate it repeatedly using Entry.MarshalBinary. For a higher level API see the functions Entry.Compose, Entry.ComposeCreate, and Entry.Create.
The commit message data format is as follows:
[Version (0x00)] + [Timestamp in ms (6 bytes BE)] + (if newChain) [ChainID Hash, sha256d(ChainID) (Bytes32)] + [Commit Weld, sha256d(hash|chainID) (Bytes32)] + [Entry Hash (Bytes32)] + [EC Cost (1 byte)] + [EC Public Key (32 Bytes)] + [Signature of data up to and including EC Cost (64 Bytes)]
func NewBytes32 ¶
NewBytes32 returns a Bytes32 populated with the data from s32, a hex encoded string.
func (Bytes32) MarshalText ¶
MarshalText encodes b as a hex string. It never returns an error.
func (*Bytes32) UnmarshalText ¶
UnmarshalText decodes a hex string with exactly 32 bytes of data into b.
type Client ¶
type Client struct { Factomd jsonrpc2.Client FactomdServer string Walletd jsonrpc2.Client WalletdServer string }
Client makes RPC requests to factomd's and factom-walletd's APIs. Client embeds two jsonrpc2.Clients, and thus also two http.Client, one for requests to factomd and one for requests to facgo butom-walletd. Use jsonrpc2.Client's BasicAuth settings to set up BasicAuth and http.Client's transport settings to configure TLS.
func NewClient ¶
func NewClient() *Client
NewClient returns a pointer to a new Client initialized with the default localhost endpoints for factomd and factom-walletd. If factomdDoer or walletdDoer is nil, the default http.Client is used. See jsonrpc2.NewClient for more details.
func (*Client) FactomdRequest ¶
func (c *Client) FactomdRequest( ctx context.Context, method string, params, result interface{}) error
FactomdRequest makes a request to factomd's v2 API.
func (*Client) GetPrivateAddresses ¶
GetPrivateAddresses queries factom-walletd for all private addresses.
func (*Client) SavePrivateAddresses ¶
SavePrivateAddresses saves many adrs with factom-walletd.
type DBlock ¶
type DBlock struct { // Computed KeyMR *Bytes32 FullHash *Bytes32 // Unmarshaled NetworkID NetworkID BodyMR *Bytes32 PrevKeyMR *Bytes32 PrevFullHash *Bytes32 Height uint32 Timestamp time.Time FBlock FBlock // DBlock.Get populates EBlocks with their ChainID, KeyMR, Timestamp, // and Height. EBlocks []EBlock // contains filtered or unexported fields }
DBlock represents a Factom Directory Block.
func (*DBlock) ClearMarshalBinaryCache ¶
func (db *DBlock) ClearMarshalBinaryCache()
ClearMarshalBinaryCache discards the cached MarshalBinary data.
Subsequent calls to MarshalBinary will re-construct the data from the fields of the DBlock.
func (DBlock) EBlock ¶
EBlock efficiently finds and returns the *EBlock in db.EBlocks for the given chainID, if it exists. Otherwise, EBlock returns nil.
This assumes that db.EBlocks ordered by ascending ChainID.
func (*DBlock) Get ¶
Get queries factomd for the Directory Block at db.Height. After a successful call, the EBlocks will all have their ChainID and KeyMR, but not their Entries. Call Get on the EBlocks individually to populate their Entries.
func (DBlock) IsPopulated ¶
IsPopulated returns true if db has already been populated by a successful call to Get.
func (DBlock) MarshalBinary ¶
MarshalBinary returns the raw DBlock data for db. This will return an error if !db.IsPopulated() or if there are more than math.MaxUint32 EBlocks. The data format is as follows.
Header
[Version byte (0x00)] + [NetworkID (4 bytes)] + [BodyMR (Bytes32)] + [PrevKeyMR (Bytes32)] + [PrevFullHash (Bytes32)] + [Timestamp (4 bytes)] + [DB Height (4 bytes)] + [EBlock Count (4 bytes)]
Body
[Admin Block ChainID (Bytes32{31:0x0a})] + [Admin Block LookupHash (Bytes32)] + [EC Block ChainID (Bytes32{31:0x0c})] + [EC Block HeaderHash (Bytes32)] + [FCT Block ChainID (Bytes32{31:0x0f})] + [FCT Block KeyMR (Bytes32)] + [ChainID 0 (Bytes32)] + [KeyMR 0 (Bytes32)] + ... + [ChainID N (Bytes32)] + [KeyMR N (Bytes32)] +
func (DBlock) MarshalBinaryLen ¶
MarshalBinaryLen returns the length of the binary encoding of db,
DBlockHeaderSize + (len(db.EBlocks)+1)*DBlockEBlockSize
func (*DBlock) UnmarshalBinary ¶
UnmarshalBinary unmarshals raw DBlock data, verifies the BodyMR, and populates db.FullHash and db.KeyMR, if nil. If db.KeyMR is populated, it is verified. The following format is expected for data.
Header
[Version byte (0x00)] + [NetworkID (4 bytes)] + [BodyMR (Bytes32)] + [PrevKeyMR (Bytes32)] + [PrevFullHash (Bytes32)] + [Timestamp (4 bytes)] + [DB Height (4 bytes)] + [EBlock Count (4 bytes)]
Body
[Admin Block ChainID (Bytes32{31:0x0a})] + [Admin Block LookupHash (Bytes32)] + [EC Block ChainID (Bytes32{31:0x0c})] + [EC Block HeaderHash (Bytes32)] + [FCT Block ChainID (Bytes32{31:0x0f})] + [FCT Block KeyMR (Bytes32)] + [ChainID 0 (Bytes32)] + [KeyMR 0 (Bytes32)] + ... + [ChainID N (Bytes32)] + [KeyMR N (Bytes32)] +
type EBlock ¶
type EBlock struct { // DBlock.Get populates the ChainID, KeyMR, Height and Timestamp. ChainID *Bytes32 KeyMR *Bytes32 // Computed Timestamp time.Time // Established by DBlock Height uint32 FullHash *Bytes32 // Computed // Unmarshaled PrevKeyMR *Bytes32 PrevFullHash *Bytes32 BodyMR *Bytes32 Sequence uint32 ObjectCount uint32 // EBlock.Get populates the Entries with their Hash and Timestamp. Entries []Entry // contains filtered or unexported fields }
EBlock represents a Factom Entry Block.
func (*EBlock) ClearMarshalBinaryCache ¶
func (eb *EBlock) ClearMarshalBinaryCache()
ClearMarshalBinaryCache discards the cached MarshalBinary data.
Subsequent calls to MarshalBinary will re-construct the data from the fields of the EBlock.
func (*EBlock) Get ¶
Get populates eb with the Entry Block corresponding to eb.KeyMR, if not nil, and otherwise the chain head for eb.ChainID.
If both eb.KeyMR and eb.ChainID are nil, an error will be returned.
After a successful call, all of eb's data will be populated, except the eb.Timestamp, which is established by the DBlock with the same Height. All eb.Entries will be populated with their Hash, ChainID, Timestamp, and Height.
func (*EBlock) GetChainHead ¶
GetChainHead populates eb.KeyMR with the chain head for eb.ChainID, the latest EBlock KeyMR, if it exists.
The returned boolean indicates whether the chain is in the process list.
If the Chain does not exist, a jsonrpc2/v14.Error will be returned indicating a Missing Chain Head.
If the Chain creation is pending, true will be returned, but the eb.KeyMR will not be populated.
func (*EBlock) GetEntries ¶
GetEntries calls eb.Get and then calls Get on each Entry in eb.Entries.
Entries are downloaded concurrently.
func (*EBlock) GetFirst ¶
GetFirst finds the first Entry Block in eb's chain, and populates eb as such.
GetFirst avoids allocating any new EBlocks by reusing eb to traverse up to the first entry block.
func (EBlock) GetPrevAll ¶
GetPrevAll returns a slice of all preceding EBlocks, in order from eb to the first EBlock in the chain. So the 0th element of the returned slice is always equal to eb. If eb is the first EBlock in the chain, then it is the only element in the slice. Like Get, if eb does not have a KeyMR, the chain head KeyMR is queried first.
If you are only interested in obtaining the first entry block in eb's chain, and not all of the intermediary ones, then use GetFirst.
func (EBlock) GetPrevBackTo ¶
GetPrevBackTo returns a slice of all preceding EBlocks, in order from eb back to, but not including, keyMR. So the 0th element of the returned slice is always equal to eb.
Get is first called on eb. So if eb does not have a KeyMR, the chain head KeyMR is queried first.
If *eb.KeyMR == *keyMR then ([]EBlock{}, nil) is returned.
If *eb.PrevKeyMR == *keyMR, then it is the only element in the slice.
If the beginning of the chain is reached without finding keyMR, then fmt.Errorf("end of chain") is returned.
func (EBlock) GetPrevN ¶
GetPrevN returns a slice of n prev EBlocks, in reverse order, including eb. So the 0th element of the returned slice is always equal to eb.
Get is first called on eb. So if eb does not have a KeyMR, the chain head KeyMR is queried first.
If n == 0, then ([]EBlock{}, nil) is returned.
If n == 1, then it is the only element in the slice.
If the beginning of the chain is reached before n EBlocks then fmt.Errorf("end of chain") is returned.
func (EBlock) IsFirst ¶
IsFirst returns true if this is the first EBlock in its chain, indicated by eb.PrevKeyMR.IsZero().
If eb is not populated, eb.IsFirst will always return false.
func (EBlock) IsPopulated ¶
IsPopulated returns true if eb has already been populated by a successful call to Get.
func (EBlock) MarshalBinary ¶
MarshalBinary returns the raw EBlock data for eb. This will return an error if !eb.IsPopulated(). The data format is as follows.
Header
[ChainID (Bytes32)] + [BodyMR (Bytes32)] + [PrevKeyMR (Bytes32)] + [PrevFullHash (Bytes32)] + [EB Sequence (uint32 BE)] + [DB Height (uint32 BE)] + [Object Count (uint32 BE)]
Body
[Object 0 (Bytes32)] // entry hash or minute marker + ... + [Object N (Bytes32)]
https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#entry-block
If EBlock was populated by a call to MarshalBinary, and ClearMar
func (EBlock) MarshalBinaryLen ¶
MarshalBinaryLen returns the length of the binary encoding of eb,
EBlockHeaderSize + len(eb.ObjectCount)*len(Bytes32{})
func (EBlock) Prev ¶
Prev returns the EBlock preceding eb, an EBlock with its KeyMR initialized to eb.PrevKeyMR and ChainID initialized to eb.ChainID.
If eb is the first Entry Block in the chain, then eb is returned. If eb is not populated, the returned EBlock will be its zero value.
func (*EBlock) SetTimestamp ¶
SetTimestamp sets the EBlock timestamp and updates all Entry Timestamps relative to this new eb.Timestamp so that the Minute Markers will still be valid during BinaryMarshaling.
func (*EBlock) UnmarshalBinary ¶
UnmarshalBinary unmarshals raw EBlock data, verifies the BodyMR, and populates eb.FullHash and eb.KeyMR, if nil. If eb.KeyMR is populated, it is verified. The following format is expected for data.
Header
[ChainID (Bytes32)] + [BodyMR (Bytes32)] + [PrevKeyMR (Bytes32)] + [PrevFullHash (Bytes32)] + [EB Sequence (uint32 BE)] + [DB Height (uint32 BE)] + [Object Count (uint32 BE)]
Body
[Object 0 (Bytes32)] // entry hash or minute marker + ... + [Object N (Bytes32)]
https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#entry-block
type ECAddress ¶
ECAddress is a Public Entry Credit Address.
func NewECAddress ¶
NewECAddress attempts to parse adrStr into a new ECAddress.
func (ECAddress) GetBalance ¶
GetBalance queries factomd for the Entry Credit Balance for adr.
func (ECAddress) GetEsAddress ¶
GetEsAddress queries factom-walletd for the EsAddress corresponding to adr.
func (ECAddress) MarshalText ¶
MarshalText encodes adr as a string using adr.String().
func (ECAddress) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte slice. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x59, 0x2a}.
func (ECAddress) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "EC".
func (ECAddress) String ¶
String encodes adr into its human readable form: base58check with adr.PrefixBytes().
func (*ECAddress) UnmarshalText ¶
UnmarshalText decodes a string with a human readable public Entry Credit address into adr.
type Entry ¶
type Entry struct { // An Entry in EBlock.Entries after a successful call to EBlock.Get has // its ChainID, Hash, and Timestamp. ChainID *Bytes32 `json:"chainid,omitempty"` Hash *Bytes32 `json:"entryhash,omitempty"` Timestamp time.Time `json:"-"` // Established by EBlock // Entry.Get populates the Content and ExtIDs. ExtIDs []Bytes `json:"extids"` Content Bytes `json:"content"` // contains filtered or unexported fields }
Entry represents a Factom Entry.
Entry can be used to Get data when the Hash is known, or submit a new Entry to a given ChainID.
func (*Entry) ClearMarshalBinaryCache ¶
func (e *Entry) ClearMarshalBinaryCache()
ClearMarshalBinaryCache discards the cached MarshalBinary data.
Subsequent calls to MarshalBinary will re-construct the data from the fields of the Entry.
func (*Entry) Compose ¶
Compose generates the commit and reveal data required to submit an Entry to factomd with Client.Commit and Client.Reveal. The Transaction ID is also returned.
The e.Hash will be populated if not nil.
If e.ChainID == nil, a new chain will be created, and e.ChainID will be populated.
If the reveal is already available to the caller, use GenerateCommit to create the commit without recreating the reveal, which is simply the raw data of an Entry.
func (*Entry) ComposeCreate ¶
ComposeCreate composes and submits an entry to factomd by calling e.Compose and then c.Commit and c.Reveal.
This does not make any calls to factom-walletd.
The e.Hash will be populated if not nil.
If e.ChainID == nil, a new chain will be created, and e.ChainID will be populated.
If successful, the Transaction ID is returned.
func (Entry) Cost ¶
Cost returns the EntryCost of e, using e.MarshalBinaryLen().
If e.ChainID == nil, the NewChainCost is added.
func (*Entry) Create ¶
Create queries factom-walletd to compose e as a new Entry, and then queries factomd to commit and reveal the new Entry or new Chain, if e.ChainID == nil.
The given ec must exist in factom-walletd's keystore.
If successful, the commit transaction ID is returned and e.Hash and e.ChainID will be populated.
func (*Entry) Get ¶
Get populates e with the Entry data for its e.Hash.
If e.Hash is nil, an error will be returned.
After a successful call e.Content, e.ExtIDs, and e.ChainID will be populated.
func (Entry) IsPopulated ¶
IsPopulated returns true if e has already been successfully populated by a call to Get.
func (Entry) MarshalBinary ¶
MarshalBinary returns the raw Entry data for e. This will return an error if !e.IsPopulated(). The data format is as follows.
[Version byte (0x00)] + [ChainID (Bytes32)] + [Total ExtID encoded length (uint16 BE)] + [ExtID 0 length (uint16)] + [ExtID 0 (Bytes)] + ... + [ExtID X length (uint16)] + [ExtID X (Bytes)] + [Content (Bytes)]
https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#entry
func (Entry) MarshalBinaryLen ¶
MarshalBinaryLen returns the total encoded length of e.
func (*Entry) UnmarshalBinary ¶
UnmarshalBinary unmarshals raw entry data into e.
If e.ChainID is not nil, it must equal the ChainID described in the data.
If e.Hash is not nil, it must equal ComputeEntryHash(data).
Like json.Unmarshal, if e.ExtIDs or e.Content are preallocated, they are reset to length zero and then appended to.
The data must encode a valid Entry. Entries are encoded as follows:
[Version byte (0x00)] + [ChainID (Bytes32)] + [Total ExtID encoded length (uint16 BE)] + [ExtID 0 length (uint16)] + [ExtID 0 (Bytes)] + ... + [ExtID X length (uint16)] + [ExtID X (Bytes)] + [Content (Bytes)]
https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#entry
type EsAddress ¶
EsAddress is the secret key to a ECAddress.
func GenerateEsAddress ¶
GenerateEsAddress generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func NewEsAddress ¶
NewEsAddress attempts to parse adrStr into a new EsAddress.
func (EsAddress) GetBalance ¶
GetBalance queries factomd for the Entry Credit Balance for adr.
func (EsAddress) MarshalText ¶
MarshalText encodes adr as a string using adr.String().
func (EsAddress) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte slice. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x5d, 0xb6}.
func (EsAddress) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "Es".
func (EsAddress) PrivateKey ¶
func (adr EsAddress) PrivateKey() ed25519.PrivateKey
PrivateKey returns the ed25519.PrivateKey for adr.
func (EsAddress) String ¶
String encodes adr into its human readable form: base58check with adr.PrefixBytes().
func (*EsAddress) UnmarshalText ¶
UnmarshalText decodes a string with a human readable secret Entry Credit address into adr.
type FAAddress ¶
FAAddress is a Public Factoid Address.
func NewFAAddress ¶
NewFAAddress attempts to parse adrStr into a new FAAddress.
func (FAAddress) GetBalance ¶
GetBalance queries factomd for the Factoid Balance for adr.
func (FAAddress) GetFsAddress ¶
GetFsAddress queries factom-walletd for the FsAddress corresponding to adr.
func (FAAddress) MarshalText ¶
MarshalText encodes adr as a string using adr.String().
func (FAAddress) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte slice. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x5f, 0xb1}.
func (FAAddress) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "FA".
func (FAAddress) String ¶
String encodes adr into its human readable form: base58check with adr.PrefixBytes().
func (*FAAddress) UnmarshalText ¶
UnmarshalText decodes a string with a human readable public Factoid address into adr.
type FBlock ¶
type FBlock struct { // Computed Fields KeyMR *Bytes32 LedgerKeyMR *Bytes32 // Header Fields BodyMR *Bytes32 PrevKeyMR *Bytes32 PrevLedgerKeyMR *Bytes32 ECExchangeRate uint64 Height uint32 // Expansion is the expansion space in the FBlock. If we do not parse // the expansion, we just store the raw bytes. Expansion Bytes // Body Fields Transactions []Transaction // Timestamp is established by the DBlock. It is only populated if the // FBlock was unmarshaled from within a DBlock. Timestamp time.Time // contains filtered or unexported fields }
FBlock represents a Factoid Block.
func (*FBlock) ClearMarshalBinaryCache ¶
func (fb *FBlock) ClearMarshalBinaryCache()
ClearMarshalBinaryCache discards the cached MarshalBinary data.
Subsequent calls to MarshalBinary will re-construct the data from the fields of the FBlock.
func (FBlock) ComputeFullHash ¶
ComputeFullHash computes the full hash of the FBlock.
func (*FBlock) Get ¶
Get queries factomd for the Factoid Block at fb.Header.Height or fb.KeyMR. After a successful call, the Transactions will all be populated.
func (FBlock) IsPopulated ¶
IsPopulated returns true if fb has already been successfully populated by a call to Get. IsPopulated returns false if fb.Transactions is nil.
func (*FBlock) MarshalBinary ¶
MarshalBinary marshals the FBlock into its binary form. If the FBlock was orignally Unmarshaled, then the cached data is re-used, so this is efficient. See ClearMarshalBinaryCache.
func (*FBlock) UnmarshalBinary ¶
UnmarshalBinary unmarshals raw directory block data.
Header
[Factoid Block ChainID (Bytes32{31:0x0f})] + [BodyMR (Bytes32)] + [PrevKeyMR (Bytes32)] + [PrevLedgerKeyMR (Bytes32)] + [Exchange Rate (8 bytes)] + [DB Height (4 bytes)] + [Header Expansion size (Bytes)] + [Header Expansion Area (Bytes)] + [Transaction Count (4 bytes)] + [Body Size (4 bytes)] +
Body
[Tx 0 (Bytes)] + ... + [Tx N (Bytes)] +
https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#factoid-block
type FsAddress ¶
FsAddress is the secret key to a FAAddress.
func GenerateFsAddress ¶
GenerateFsAddress generates a secure random private Factoid address using crypto/rand.Random as the source of randomness.
func NewFsAddress ¶
NewFsAddress attempts to parse adrStr into a new FsAddress.
func (FsAddress) GetBalance ¶
GetBalance queries factomd for the Factoid Balance for adr.
func (FsAddress) MarshalText ¶
MarshalText encodes adr as a string using adr.String().
func (FsAddress) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte slice. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x64, 0x78}.
func (FsAddress) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "Fs".
func (FsAddress) PrivateKey ¶
func (adr FsAddress) PrivateKey() ed25519.PrivateKey
PrivateKey returns the ed25519.PrivateKey for adr.
func (FsAddress) String ¶
String encodes adr into its human readable form: base58check with adr.PrefixBytes().
func (*FsAddress) UnmarshalText ¶
UnmarshalText decodes a string with a human readable secret Factoid address into adr.
type Heights ¶
type Heights struct { // The current directory block height of the local factomd node. DirectoryBlock uint32 `json:"directoryblockheight"` // The current block being worked on by the leaders in the network. // This block is not yet complete, but all transactions submitted will // go into this block (depending on network conditions, the transaction // may be delayed into the next block) Leader uint32 `json:"leaderheight"` // The height at which the factomd node has all the entry blocks. // Directory blocks are obtained first, entry blocks could be lagging // behind the directory block when syncing. EntryBlock uint32 `json:"entryblockheight"` // The height at which the local factomd node has all the entries. If // you added entries at a block height above this, they will not be // able to be retrieved by the local factomd until it syncs further. Entry uint32 `json:"entryheight"` }
Heights contains all of the distinct heights for a factomd node and the Factom network.
type ID1Key ¶
ID1Key is the id1 public key for an identity.
func (ID1Key) MarshalText ¶
MarshalText encodes key as a string using key.String().
func (ID1Key) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x3f, 0xbe, 0xba}.
func (ID1Key) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "id1".
func (ID1Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*ID1Key) UnmarshalText ¶
UnmarshalText decodes a string with a human readable id1 key into key.
type ID2Key ¶
ID2Key is the id2 public key for an identity.
func (ID2Key) MarshalText ¶
MarshalText encodes key as a string using key.String().
func (ID2Key) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x3f, 0xbe, 0xd8}.
func (ID2Key) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "id2".
func (ID2Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*ID2Key) UnmarshalText ¶
UnmarshalText decodes a string with a human readable id2 key into key.
type ID3Key ¶
ID3Key is the id3 public key for an identity.
func (ID3Key) MarshalText ¶
MarshalText encodes key as a string using key.String().
func (ID3Key) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x3f, 0xbe, 0xf6}.
func (ID3Key) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "id3".
func (ID3Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*ID3Key) UnmarshalText ¶
UnmarshalText decodes a string with a human readable id3 key into key.
type ID4Key ¶
ID4Key is the id4 public key for an identity.
func (ID4Key) MarshalText ¶
MarshalText encodes key as a string using key.String().
func (ID4Key) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x3f, 0xbf, 0x14}.
func (ID4Key) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "id4".
func (ID4Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*ID4Key) UnmarshalText ¶
UnmarshalText decodes a string with a human readable id4 key into key.
type Identity ¶
Identity represents the Token Issuer's Identity Chain and the public ID1Key.
func (Identity) IsPopulated ¶
IsPopulated returns true if the Identity has been populated with an ID1Key.
func (*Identity) UnmarshalBinary ¶
UnmarshalBinary calls i.Entry.UnmarshalBinary and then performs additional validation checks on the ChainID and NameID formats.
type NetworkID ¶
type NetworkID [4]byte
NetworkID represents the 4 byte magic number that helps identify distinct Factom networks.
NetworkID conforms to the flag.Value interface.
func LocalnetID ¶
func LocalnetID() NetworkID
LocalnetID returns the Localnet NetworkID, 0xFA92E5A4.
func (NetworkID) IsCustom ¶
IsCustom returns true if n is not the Mainnet, Testnet, or Localnet NetworkID.
func (NetworkID) IsLocalnet ¶
IsLocalnet returns true if n is the Localnet NetworkID.
type PendingEntries ¶
type PendingEntries []Entry
PendingEntries is a list of pending entries which may or may not be revealed. If the entry's ChainID is not nil, then its data has been revealed and can be queried from factomd.
func (PendingEntries) Entries ¶
func (pe PendingEntries) Entries(chainID *Bytes32) []Entry
Entries efficiently finds and returns all entries in pe for the given chainID, if any exist. Otherwise, Entries returns nil.
func (*PendingEntries) Get ¶
func (pe *PendingEntries) Get(ctx context.Context, c *Client) error
Get returns all pending entries sorted by descending ChainID, and then order they were originally returned. Pending Entries that are committed but not revealed have a nil ChainID and are at the end of the pe slice.
type RCD ¶
type RCD []byte
RCD is a Redeem Condition Datastructure. It is just a byte slice with special meaning.
func (RCD) SignatureBlockSize ¶
SignatureBlockSize returns the expected size of the signature block this RCD requires.
func (RCD) Type ¶
Type returns the first byte of rcd as an RCDType.
This will panic of len(rcd) < 1.
func (*RCD) UnmarshalBinary ¶
UnmarshalBinary parses the first RCD out of data. Use len(rcd) to determine how many bytes of data were read.
func (RCD) Validate ¶
Validate verifies the RCD against the given sig and msg. Only RCDTypes in the whitelist are permitted. If no whitelist is provided all supported RCDTypes are allowed.
func (RCD) ValidateType01 ¶
ValidateType01 validates the RCD against sig and msg and ensures that the RCD is RCDType01.
type RCDSignature ¶
RCDSignature relates an RCD and a corresponding Signature of a signed Transaction.
func (RCDSignature) IsPopulated ¶
func (rs RCDSignature) IsPopulated() bool
IsPopulated returns true if s has already been successfully populated by a call to Get. IsPopulated returns false if s.SignatureBlock or s.ReedeemCondition are nil
func (RCDSignature) Len ¶
func (rs RCDSignature) Len() int
Len is the total size of the RCD and Signature.
func (RCDSignature) MarshalBinary ¶
func (rs RCDSignature) MarshalBinary() ([]byte, error)
MarshalBinary concatenates the RCD and the signature.
func (*RCDSignature) UnmarshalBinary ¶
func (rs *RCDSignature) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshals the variable length RCD and Signature block into rs.
Use Len to determine how much data was read.
func (RCDSignature) ValidateType01 ¶
func (rs RCDSignature) ValidateType01(msg []byte) error
ValidateType01 validates the RCD and Signature against the msg, which is normally the Transaction Binary Ledger.
type RCDSigner ¶
type RCDSigner interface { // RCD constructs the RCD. RCD() RCD // Sign the msg. Sign(msg []byte) []byte }
RCDSigner is the interface implemented by types that can generate Redeem Condition Datastructures and the corresponding signatures to validate them.
type RCDType ¶
type RCDType byte
RCDType is the magic number that represents the RCD type. Currently this only takes up one byte but techincally it is a varintf. Down the road the underlying type may change to allow for longer IDs for RCD Types.
type SK1Key ¶
SK1Key is the sk1 secret key for an identity.
func GenerateSK1Key ¶
GenerateSK1Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func (SK1Key) MarshalText ¶
MarshalText encodes key as a string using key.String().
func (SK1Key) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x4d, 0xb6, 0xc9}.
func (SK1Key) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "sk1".
func (SK1Key) PrivateKey ¶
func (key SK1Key) PrivateKey() ed25519.PrivateKey
PrivateKey returns the ed25519.PrivateKey for key.
func (SK1Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*SK1Key) UnmarshalText ¶
UnmarshalText decodes a string with a human readable sk1 key into key.
type SK2Key ¶
SK2Key is the sk2 secret key for an identity.
func GenerateSK2Key ¶
GenerateSK2Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func (SK2Key) MarshalText ¶
MarshalText encodes key as a string using key.String().
func (SK2Key) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x4d, 0xb6, 0xe7}.
func (SK2Key) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "sk2".
func (SK2Key) PrivateKey ¶
func (key SK2Key) PrivateKey() ed25519.PrivateKey
PrivateKey returns the ed25519.PrivateKey for key.
func (SK2Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*SK2Key) UnmarshalText ¶
UnmarshalText decodes a string with a human readable sk2 key into key.
type SK3Key ¶
SK3Key is the sk3 secret key for an identity.
func GenerateSK3Key ¶
GenerateSK3Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func (SK3Key) MarshalText ¶
MarshalText encodes key as a string using key.String().
func (SK3Key) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x4d, 0xb7, 0x05}.
func (SK3Key) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "sk3".
func (SK3Key) PrivateKey ¶
func (key SK3Key) PrivateKey() ed25519.PrivateKey
PrivateKey returns the ed25519.PrivateKey for key.
func (SK3Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*SK3Key) UnmarshalText ¶
UnmarshalText decodes a string with a human readable sk3 key into key.
type SK4Key ¶
SK4Key is the sk4 secret key for an identity.
func GenerateSK4Key ¶
GenerateSK4Key generates a secure random private Entry Credit address using crypto/rand.Random as the source of randomness.
func (SK4Key) MarshalText ¶
MarshalText encodes key as a string using key.String().
func (SK4Key) PrefixBytes ¶
PrefixBytes returns the two byte prefix for the address type as a byte array. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns []byte{0x4d, 0xb7, 0x23}.
func (SK4Key) PrefixString ¶
PrefixString returns the two prefix bytes for the address type as an encoded string. Note that the prefix for a given address type is always the same and does not depend on the address value. Returns "sk4".
func (SK4Key) PrivateKey ¶
func (key SK4Key) PrivateKey() ed25519.PrivateKey
PrivateKey returns the ed25519.PrivateKey for key.
func (SK4Key) String ¶
String encodes key into its human readable form: a base58check string with key.PrefixBytes().
func (*SK4Key) UnmarshalText ¶
UnmarshalText decodes a string with a human readable sk4 key into key.
type Transaction ¶
type Transaction struct { // ID the sha256 hash of the binary Transaction ledger, which includes // the header, timestamp salt, and all inputs and outputs. ID *Bytes32 // Timestamp is established by the FBlock. It is only populated if the // Transaction was unmarshaled from within an FBlock Timestamp time.Time // TimestampSalt is accurate to the millisecond TimestampSalt time.Time // Totals all denoted in factoshis. Populated by UnmarshalBinary. TotalIn, TotalFCTOut, TotalECOut, TotalBurn uint64 FCTInputs []AddressAmount FCTOutputs []AddressAmount ECOutputs []AddressAmount Signatures []RCDSignature // contains filtered or unexported fields }
Transaction is a Factoid Transaction which is stored in the FBlock.
Transactions can be between FAAddresses, or from an FAAddress to an ECAddress.
Transaction amounts are all delimited in Factoshis.
func (*Transaction) ClearMarshalBinaryCache ¶
func (tx *Transaction) ClearMarshalBinaryCache()
ClearMarshalBinaryCache discards the cached MarshalBinary data.
Subsequent calls to MarshalBinary will re-construct the data from the fields of the DBlock.
func (Transaction) IsPopulated ¶
func (tx Transaction) IsPopulated() bool
IsPopulated returns true if tx has already been successfully populated by a call to Get. IsPopulated returns false if tx.FCTInputs is empty, or if tx.Signatures is not equal in length to the tx.FCTInputs, or if tx.TimestampSalt is zero.
func (Transaction) MarshalBinary ¶
func (tx Transaction) MarshalBinary() ([]byte, error)
MarshalBinary marshals the Transaction into its binary form. If the Transaction was orignally Unmarshaled, then the cached data is re-used, so this is efficient. See ClearMarshalBinaryCache.
This assumes that the Transaction has all signatures in place already. See Transaction.Sign for signing transactions.
func (Transaction) MarshalBinaryLedger ¶
func (tx Transaction) MarshalBinaryLedger() ([]byte, error)
MarshalBinaryLedger marshals the header, inputs, outputs, and EC outputs of the Transaction. This is so that the data can be conveniently signed or hashed.
func (Transaction) MarshalBinaryLen ¶
func (tx Transaction) MarshalBinaryLen() int
MarshalBinaryLen efficiently calculates the full Transaction size. The cached binary marshal data is used if populated.
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(signingSet ...RCDSigner) ([]byte, error)
Sign populates the Signatures of the tx with the given signingSet, which must correspond to the tx.FCTInputs. The complete binary marshaled Transaction is returned.
func (*Transaction) UnmarshalBinary ¶
func (tx *Transaction) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshals and validates the first Transaction from data, which may include subsequent Transactions. If no error is returned, the Transaction is valid, including all RCDs and signatures.
Use MarshalBinaryLen to efficiently determine the number of bytes read from data.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package fat0 provides data types corresponding to valid FAT-0 entries for Transaction and Issuance as well as methods for validating the structure and content of the factom entry.
|
Package fat0 provides data types corresponding to valid FAT-0 entries for Transaction and Issuance as well as methods for validating the structure and content of the factom entry. |
Package varintf implements Factom's varInt_F specification.
|
Package varintf implements Factom's varInt_F specification. |