p5

package
v0.0.0-...-c2f1f9c Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TOKENUNIT = "pingala"

Variables

This section is empty.

Functions

func DecryptMessageWithPrivateKey

func DecryptMessageWithPrivateKey(privateKey *rsa.PrivateKey, encrypted []byte) []byte

func EncryptMessageWithPublicKey

func EncryptMessageWithPublicKey(publicKey *rsa.PublicKey, message string) []byte

func GenDigest

func GenDigest(hash hash.Hash, message []byte) []byte

GenDigest func returns a hash for both a)GenSignature func and b)VerifySignature

func GenerateHashForKey

func GenerateHashForKey(label string) hash.Hash

generateHashForKey func creates a hash for id

func GeneratePubPrivKeyPair

func GeneratePubPrivKeyPair() (*rsa.PrivateKey, *rsa.PublicKey)

generatePubPrivKeyPair func creates key pair pub - priv

func GetHashOfPublicKey

func GetHashOfPublicKey(pid *PublicIdentity) string

GetHashOfPubId

func GetKeyForBook

func GetKeyForBook(publicKey *rsa.PublicKey) string

func VerifySingature

func VerifySingature(senderPubKey *rsa.PublicKey, message []byte, sig []byte) bool

func VerifyTxSig

func VerifyTxSig(fromPid PublicIdentity, tx Transaction, txSig []byte) bool

Types

type BalanceBook

type BalanceBook struct {
	Book p1.MerklePatriciaTrie //key - hashOfPubKey and Value - balance

	// key - Requirement transaction id -||- value - BorrowingTransaction
	Promised map[string]BorrowingTransaction
	// contains filtered or unexported fields
}

func NewBalanceBook

func NewBalanceBook() BalanceBook

func (*BalanceBook) BuildBalanceBook

func (bb *BalanceBook) BuildBalanceBook(chain p2.Blockchain, fromHeight int32)

func (*BalanceBook) CheckAmountPromisedByOne

func (bb *BalanceBook) CheckAmountPromisedByOne(pid PublicIdentity) float64

func (*BalanceBook) GetBalanceFromKey

func (bb *BalanceBook) GetBalanceFromKey(PublicKeyHashStr string) float64

func (*BalanceBook) GetBalanceFromPublicKey

func (bb *BalanceBook) GetBalanceFromPublicKey(publicKey *rsa.PublicKey) float64

func (*BalanceBook) GetKey

func (bb *BalanceBook) GetKey(publicKey *rsa.PublicKey) string

GetKey func takes in PublicKey and returns Key for Book

func (*BalanceBook) PutTxInPromised

func (bb *BalanceBook) PutTxInPromised(tx Transaction)

func (*BalanceBook) Show

func (bb *BalanceBook) Show() string

func (*BalanceBook) ShowPromised

func (bb *BalanceBook) ShowPromised() string

func (*BalanceBook) TransferPromisesMade

func (bb *BalanceBook) TransferPromisesMade(btx BorrowingTransaction)

func (*BalanceBook) UpdateABalanceBookForTx

func (bb *BalanceBook) UpdateABalanceBookForTx(tx Transaction)

func (*BalanceBook) UpdateABalanceInBook

func (bb *BalanceBook) UpdateABalanceInBook(PublicKeyHashStr string, updateBalanceBy float64)

func (*BalanceBook) UpdateABalanceInPromised

func (bb *BalanceBook) UpdateABalanceInPromised(tx Transaction, btx BorrowingTransaction)

type BlockChainHolders

type BlockChainHolders struct {
	Holders map[string]PublicIdentity
	// contains filtered or unexported fields
}

func NewBlockChainHolders

func NewBlockChainHolders() BlockChainHolders

func (*BlockChainHolders) AddBlockChainHolder

func (BCH *BlockChainHolders) AddBlockChainHolder(addr string, pid PublicIdentity)

func (*BlockChainHolders) DeleteBlockChainHolder

func (BCH *BlockChainHolders) DeleteBlockChainHolder(addr string)

func (*BlockChainHolders) Show

func (BCH *BlockChainHolders) Show() string

type BorrowingTransaction

type BorrowingTransaction struct {
	BorrowingTxId string        `json:"borrowingtxid"`
	BorrowingTx   Transaction   `json:"borrowingtx"`
	PromisesMade  []Transaction `json:"promisesmade"` // key - transaction id (Lending) // todo todo -- changed from map to array
	PromisedValue float64       `json:"promisedvalue"`
}

func NewBorrowingTransaction

func NewBorrowingTransaction(tx Transaction) BorrowingTransaction

func (*BorrowingTransaction) CheckForEnoughPromises

func (btx *BorrowingTransaction) CheckForEnoughPromises() bool

func (*BorrowingTransaction) EncodeTojsonString

func (btx *BorrowingTransaction) EncodeTojsonString() string

type BorrowingTransactions

type BorrowingTransactions struct {
	BorrowingTxs map[string]Transaction // key - BorrowingTxId value - txJson
	Borrower     map[string]string      //json of pid of borrower
}

func BuildBorrowingTransactions

func BuildBorrowingTransactions(chains []p2.Blockchain) BorrowingTransactions

func NewBorrowingTransactions

func NewBorrowingTransactions() BorrowingTransactions

type ClientId

type ClientId struct {
	PrivateKey *rsa.PrivateKey `json:"privateKey"`
	PublicKey  *rsa.PublicKey  `json:"publicKey"`
	//HashForKey 	hash.Hash
	Label string `json:"label"`
}

func ExistingClientId

func ExistingClientId(priv *rsa.PrivateKey, pub *rsa.PublicKey, label string) ClientId

func JsonToClientId

func JsonToClientId(jsonStr string) (ClientId, error)

func NewClientId

func NewClientId(label string) ClientId

func (*ClientId) ClientIdToJsonByteArray

func (id *ClientId) ClientIdToJsonByteArray() []byte

func (*ClientId) GenSignature

func (id *ClientId) GenSignature(message []byte) []byte

func (*ClientId) GetMyPublicIdentity

func (id *ClientId) GetMyPublicIdentity() PublicIdentity

type Identity

type Identity struct {
	PublicKey *rsa.PublicKey `json:"publicKey"`
	//HashForKey 	hash.Hash
	Label string `json:"label"`
	// contains filtered or unexported fields
}

func NewIdentity

func NewIdentity(label string) Identity

func (*Identity) GenSignature

func (id *Identity) GenSignature(message []byte) []byte

func (*Identity) GetMyPrivateKey

func (id *Identity) GetMyPrivateKey() *rsa.PrivateKey

func (*Identity) GetMyPublicIdentity

func (id *Identity) GetMyPublicIdentity() PublicIdentity

type PublicIdentity

type PublicIdentity struct {
	PublicKey *rsa.PublicKey `json:"publicKey"`
	//HashForKey 	hash.Hash 		`json="hashForKey"`
	Label string `json:"label"`
}

func JsonToPublicIdentity

func JsonToPublicIdentity(str string) PublicIdentity

func (*PublicIdentity) PublicIdentityToJson

func (pid *PublicIdentity) PublicIdentityToJson() string

type Transaction

type Transaction struct {
	Id        string         `json:"id"`
	From      PublicIdentity `json:"from"`
	To        PublicIdentity `json:"to"` //if To is empty then its a borrowing tx
	ToTxId    string         `json:"toTxId"`
	Tokens    float64        `json:"tokens"`
	Fees      float64        `json:"fees"`
	TxType    string         `json:"txtype"`
	Timestamp time.Time      `json:"timestamp"`
}

func JsonToTransaction

func JsonToTransaction(txJson string) Transaction

func NewTransaction

func NewTransaction(from PublicIdentity, to PublicIdentity, toTxId string, tokens float64, fees float64, txType string) Transaction

func (*Transaction) CreateTxSig

func (tx *Transaction) CreateTxSig(fromCid ClientId) []byte

func (*Transaction) CreateTxSigForMiner

func (tx *Transaction) CreateTxSigForMiner(fromId Identity) []byte

func (*Transaction) Show

func (tx *Transaction) Show() string

func (*Transaction) TransactionToJson

func (tx *Transaction) TransactionToJson() string

func (*Transaction) TransactionToJsonByteArray

func (tx *Transaction) TransactionToJsonByteArray() []byte

type TransactionBeat

type TransactionBeat struct {
	Tx      Transaction
	FromPid PublicIdentity
	TxSig   []byte
	Hops    int
}

func DecodeToTransactionBeat

func DecodeToTransactionBeat(transactionBeatJson []byte) TransactionBeat

DecodeToHeartBeatData func decodes json string to HeartBeatData

func NewTransactionBeat

func NewTransactionBeat(tx Transaction, fromPid PublicIdentity, fromSig []byte) TransactionBeat

func PrepareTransactionBeat

func PrepareTransactionBeat(tx Transaction, cid ClientId) TransactionBeat

func (*TransactionBeat) EncodeToJson

func (data *TransactionBeat) EncodeToJson() string

EncodeToJson func encodes HeartBeatData to json string

func (*TransactionBeat) EncodeToJsonByteArray

func (data *TransactionBeat) EncodeToJsonByteArray() []byte

EncodeToJson func encodes HeartBeatData to json byte array

func (*TransactionBeat) VerifyTxSigInTxBeat

func (data *TransactionBeat) VerifyTxSigInTxBeat() bool

type TransactionPool

type TransactionPool struct {
	Pool      map[string]Transaction `json:"pool"`
	Confirmed map[string]bool        `json:"confirmed"`
	// contains filtered or unexported fields
}

this is for mining

func NewTransactionPool

func NewTransactionPool() TransactionPool

func (*TransactionPool) AddPoolToTransactionPool

func (txp *TransactionPool) AddPoolToTransactionPool(recvTxp TransactionPool)

func (*TransactionPool) AddToTransactionPool

func (txp *TransactionPool) AddToTransactionPool(tx Transaction)

func (*TransactionPool) DeleteFromTransactionPool

func (txp *TransactionPool) DeleteFromTransactionPool(txid string)

func (*TransactionPool) GetTransactionPoolJsonObj

func (txp *TransactionPool) GetTransactionPoolJsonObj() TransactionPoolJson

Copy func returns a copy of the peerMap

func (*TransactionPool) ReadFromTransactionPool

func (txp *TransactionPool) ReadFromTransactionPool(n int) map[string]Transaction

func (*TransactionPool) Show

func (txp *TransactionPool) Show() string

type TransactionPoolJson

type TransactionPoolJson struct {
	Pool map[string]Transaction `json:"pool"`
}

func DecodeJsonToTransactionPoolJson

func DecodeJsonToTransactionPoolJson(jsonStr string) TransactionPoolJson

func (*TransactionPoolJson) EncodeToJsonTransactionPoolJson

func (txpj *TransactionPoolJson) EncodeToJsonTransactionPoolJson() string

type Wallet

type Wallet struct {
	Balance float64
	Unit    string
	// contains filtered or unexported fields
}

func NewWallet

func NewWallet() Wallet

func (*Wallet) Show

func (w *Wallet) Show() string

func (*Wallet) Update

func (w *Wallet) Update(value float64)

Jump to

Keyboard shortcuts

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