consensus

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 23 Imported by: 19

Documentation

Index

Constants

View Source
const (
	ErrUnknown    = iota
	ErrInvalidTip = iota
	ErrInvalidSig = iota
)
View Source
const (
	TreePathForAuthentications = "_tupelo/authentications"
	TreePathForTokens          = "_tupelo/tokens"
	TreePathForStake           = "_tupelo/stake"
	TreePathForData            = "data"

	TokenMintLabel    = "mints"
	TokenSendLabel    = "sends"
	TokenReceiveLabel = "receives"
)
View Source
const (
	MonetaryPolicyLabel = "monetaryPolicy"
	TokenBalanceLabel   = "balance"
)
View Source
const MessageType_AddBlock = "ADD_BLOCK"
View Source
const MessageType_GetDiffNodes = "GET_DIFF_NODES"
View Source
const MessageType_TipRequest = "TIP_REQUEST"

Variables

Functions

func AddrToDid

func AddrToDid(addr string) string

func BlockToHash

func BlockToHash(block chaintree.Block) ([]byte, error)

func ConflictSetID

func ConflictSetID(objectID []byte, height uint64) string

func DecodePath

func DecodePath(path string) ([]string, error)

func DidToAddr

func DidToAddr(did string) string

func EcdsaPubkeyToDid

func EcdsaPubkeyToDid(key ecdsa.PublicKey) string

func EstablishTokenTransaction

func EstablishTokenTransaction(chainTreeDID string, tree *dag.Dag, txn *transactions.Transaction) (newTree *dag.Dag, valid bool, codedErr chaintree.CodedError)

func GetSenderDagFromReceive

func GetSenderDagFromReceive(payload *transactions.ReceiveTokenPayload) (*dag.Dag, chaintree.CodedError)

GetSenderDagFromReceive takes the receive token payload and returns the SendToken dag that was included in the ReceiveTokenPayload

func GetSignable

func GetSignable(sig *signatures.TreeState) []byte

func IsBlockSignedBy

func IsBlockSignedBy(ctx context.Context, blockWithHeaders *chaintree.BlockWithHeaders, addr string) (bool, error)

func MintTokenTransaction

func MintTokenTransaction(chainTreeDID string, tree *dag.Dag, txn *transactions.Transaction) (newTree *dag.Dag, valid bool, codedErr chaintree.CodedError)

func MustObjToHash

func MustObjToHash(payload interface{}) []byte

func NewEmptyTree

func NewEmptyTree(ctx context.Context, did string, nodeStore nodestore.DagStore) *dag.Dag

func NodeToObj

func NodeToObj(node format.Node) (obj interface{}, err error)

func ObjToHash

func ObjToHash(payload interface{}) ([]byte, error)

func PassPhraseKey

func PassPhraseKey(passPhrase, salt []byte) (*ecdsa.PrivateKey, error)

PassPhraseKey implements a known passphrase -> private Key generator following very closely the params from Warp Wallet. The only difference here is that the N on scrypt is 256 instead of 218 because go requires N to be a power of 2. from the Warp Wallet ( https://keybase.io/warp/warp_1.0.9_SHA256_a2067491ab582bde779f4505055807c2479354633a2216b22cf1e92d1a6e4a87.html ): s1 = scrypt(key=(passphrase||0x1), salt=(salt||0x1), N=218, r=8, p=1, dkLen=32) s2 = pbkdf2(key=(passphrase||0x2), salt=(salt||0x2), c=216, dkLen=32, prf=HMAC_SHA256) keypair = generate_bitcoin_keypair(s1 ⊕ s2)

func ReceiveTokenTransaction

func ReceiveTokenTransaction(_ string, tree *dag.Dag, txn *transactions.Transaction) (newTree *dag.Dag, valid bool, codedError chaintree.CodedError)

func RequestID

func RequestID(req *services.AddBlockRequest) []byte

func SendTokenTransaction

func SendTokenTransaction(chainTreeDID string, tree *dag.Dag, txn *transactions.Transaction) (newTree *dag.Dag, valid bool, codedErr chaintree.CodedError)

func SetDataTransaction

func SetDataTransaction(_ string, tree *dag.Dag, txn *transactions.Transaction) (newTree *dag.Dag, valid bool, codedErr chaintree.CodedError)

SetDataTransaction just sets a path in tree/data to arbitrary data.

func SetOwnershipTransaction

func SetOwnershipTransaction(_ string, tree *dag.Dag, txn *transactions.Transaction) (newTree *dag.Dag, valid bool, codedErr chaintree.CodedError)

SetOwnershipTransaction changes the ownership of a tree by adding a public key array to /_tupelo/authentications

func SignBlock

func SignBlock(ctx context.Context, blockWithHeaders *chaintree.BlockWithHeaders, key *ecdsa.PrivateKey) (*chaintree.BlockWithHeaders, error)

func StakeTransaction

func StakeTransaction(_ string, tree *dag.Dag, txn *transactions.Transaction) (newTree *dag.Dag, valid bool, codedErr chaintree.CodedError)

THIS IS A pre-ALPHA TRANSACTION AND NO RULES ARE ENFORCED! Anyone can stake and join a group with no consequences. additionally, it only allows staking a single group at the moment

func TokenPath

func TokenPath(tokenName *TokenName) ([]string, error)

func TokenPayloadForTransaction

func TokenPayloadForTransaction(chain *chaintree.ChainTree, tokenName *TokenName, sendTokenTxId string, sendTxProof *gossip.Proof) (*transactions.TokenPayload, error)

func TokenTransactionCidsForType

func TokenTransactionCidsForType(tree *dag.Dag, tokenName *TokenName, txType string) ([]cid.Cid, error)

Types

type ErrorCode

type ErrorCode struct {
	Code int
	Memo string
}

func (*ErrorCode) Error

func (e *ErrorCode) Error() string

func (*ErrorCode) GetCode

func (e *ErrorCode) GetCode() int

type GetDiffNodesRequest

type GetDiffNodesRequest struct {
	PreviousTip *cid.Cid
	NewTip      *cid.Cid
}

type GetDiffNodesResponse

type GetDiffNodesResponse struct {
	Nodes [][]byte
}

type SignatureMap

type SignatureMap map[string]*signatures.Signature

func (SignatureMap) Merge

func (sm SignatureMap) Merge(other SignatureMap) SignatureMap

Merge returns a new SignatatureMap composed of the original with the other merged in other wins when both SignatureMaps have signatures

func (SignatureMap) Only

func (sm SignatureMap) Only(keys []string) SignatureMap

Only returns a new SignatureMap with only keys in the keys slice argument

func (SignatureMap) Subtract

func (sm SignatureMap) Subtract(other SignatureMap) SignatureMap

Subtract returns a new SignatureMap with only the new signatures in other.

type SignedChainTree

type SignedChainTree struct {
	ChainTree *chaintree.ChainTree
	Proof     *gossip.Proof
}

func NewSignedChainTree

func NewSignedChainTree(ctx context.Context, key ecdsa.PublicKey, nodeStore nodestore.DagStore) (*SignedChainTree, error)

func NewSignedChainTreeFromChainTree

func NewSignedChainTreeFromChainTree(tree *chaintree.ChainTree) *SignedChainTree

func (*SignedChainTree) Authentications

func (sct *SignedChainTree) Authentications() ([]string, error)

func (*SignedChainTree) Id

func (sct *SignedChainTree) Id() (string, error)

func (*SignedChainTree) IsGenesis

func (sct *SignedChainTree) IsGenesis() bool

func (*SignedChainTree) MustId

func (sct *SignedChainTree) MustId() string

func (*SignedChainTree) Tip

func (sct *SignedChainTree) Tip() cid.Cid

type StandardHeaders

type StandardHeaders struct {
	Signatures SignatureMap `refmt:"signatures,omitempty" json:"signatures,omitempty" cbor:"signatures,omitempty"`
}

type TipRequest

type TipRequest struct {
	ChainId string
}

type TipResponse

type TipResponse struct {
	ChainId   string
	Tip       *cid.Cid
	Signature signatures.Signature
}

type TipSignature

type TipSignature struct {
	Tip       *cid.Cid
	Signature signatures.Signature
}

type Token

type Token struct {
	MonetaryPolicy *cid.Cid
	Mints          *cid.Cid
	Sends          *cid.Cid
	Receives       *cid.Cid
	Balance        uint64
}

TODO: Consider removing from the CBOR atlas to allow us to resolve the child nodes into their native objects directly by navigating through Token nodes. This would require changing the balance field to a composite object so we can resolve the balance without integer overflow

type TokenLedger

type TokenLedger interface {
	TokenExists() (bool, error)
	Balance() (uint64, error)
	EstablishToken(monetaryPolicy transactions.TokenMonetaryPolicy) (*dag.Dag, error)
	MintToken(amount uint64) (*dag.Dag, error)
	SendToken(txId, destination string, amount uint64) (*dag.Dag, error)
	ReceiveToken(sendTokenTxId string, amount uint64) (*dag.Dag, error)
}

type TokenMint

type TokenMint struct {
	Amount uint64
}

TODO: These token struct types should probably be protobufs in the messages repo.

type TokenName

type TokenName struct {
	ChainTreeDID string
	LocalName    string
}

func CanonicalTokenName

func CanonicalTokenName(tree *dag.Dag, defaultChainTreeDID, tokenName string, requireDefault bool) (*TokenName, error)

func GetTokenNameFromReceive

func GetTokenNameFromReceive(senderDag *dag.Dag) (*TokenName, chaintree.CodedError)

GetTokenNameFromReceive takes the SendToken that was included in a ReceiveTokenPayload and returns the name of the sent token.

func TokenNameFromString

func TokenNameFromString(tokenName string) TokenName

func (*TokenName) IsCanonical

func (tn *TokenName) IsCanonical() bool

func (*TokenName) String

func (tn *TokenName) String() string

type TokenReceive

type TokenReceive struct {
	SendTokenTransactionId string
	Amount                 uint64
}

type TokenSend

type TokenSend struct {
	Id          string
	Amount      uint64
	Destination string
}

func GetSendTokenFromReceive

func GetSendTokenFromReceive(senderDag *dag.Dag, tokenName *TokenName) (*TokenSend, chaintree.CodedError)

GetSendTokenFromReceive takes DAG that is part of the ReceiveTokenPayload and returns The TokenSend for the specified tokenName

type TreeLedger

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

func NewTreeLedger

func NewTreeLedger(tree *dag.Dag, tokenName *TokenName) *TreeLedger

func (*TreeLedger) Balance

func (l *TreeLedger) Balance() (uint64, error)

func (*TreeLedger) EstablishToken

func (l *TreeLedger) EstablishToken(monetaryPolicy transactions.TokenMonetaryPolicy) (*dag.Dag, error)

func (*TreeLedger) MintToken

func (l *TreeLedger) MintToken(amount uint64) (*dag.Dag, error)

func (*TreeLedger) ReceiveToken

func (l *TreeLedger) ReceiveToken(sendTokenTxId string, amount uint64) (*dag.Dag, error)

func (*TreeLedger) SendToken

func (l *TreeLedger) SendToken(txId, destination string, amount uint64) (*dag.Dag, error)

func (*TreeLedger) TokenExists

func (l *TreeLedger) TokenExists() (bool, error)

Jump to

Keyboard shortcuts

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