contracts

package
v0.0.0-...-f0b43a4 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contract

type Contract struct {
	Version         uint16
	SenderPubKey    *ecdsa.PublicKey
	SigLen          uint8  // len of the signature
	Signature       []byte // size varies
	RecipPubKeyHash []byte // 32 bytes
	Value           uint64
	StateNonce      uint64
}

Version Sender Public Key Signature Length Signature Recipient Public Key Hash Value

func New

func New(version uint16, sender *ecdsa.PrivateKey, recipient []byte, value uint64, nextStateNonce uint64) (*Contract, error)

version field comes from version parameter sender public key comes from sender private key signature comes from calling sign contract signature length comes from signature recipient pk hash comes from sha-256 hash of rpk value is value parameter returns contract struct

func (*Contract) Deserialize

func (c *Contract) Deserialize(b []byte) error

Deserialize into a struct

func (*Contract) Equals

func (contract1 *Contract) Equals(contract2 Contract) bool

compare two contracts and return true only if all fields match

func (*Contract) Marshal

func (c *Contract) Marshal() (JSONContract, error)

Marshal takes a Contract and returns a JSONContract

func (*Contract) Serialize

func (c *Contract) Serialize() ([]byte, error)

// Serialize all fields of the contract

func (*Contract) Sign

func (c *Contract) Sign(sender *ecdsa.PrivateKey) error

hashed contract = sha 256 hash ( version + spubkey + rpubkeyhash + value) signature = Sign ( hashed contract, sender private key ) sig len = signature length siglen and sig go into respective fields in contract

func (Contract) ToString

func (c Contract) ToString() string

ToString takes in a Contract and return a string version

type JSONContract

type JSONContract struct {
	Version                uint16
	SenderPublicKey        string
	SignatureLength        uint8
	Signature              string
	RecipientWalletAddress string
	Value                  uint64
	StateNonce             uint64
}

func (*JSONContract) Unmarshal

func (mc *JSONContract) Unmarshal() (Contract, error)

Unmarshal takes a JSONContract and returns a Contract

Jump to

Keyboard shortcuts

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