sctransaction

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: Apache-2.0, BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Overview

implement smart contract transaction. smart contract transaction is value transaction with special payload

Index

Constants

View Source
const (
	RequestCodeReserved          = uint16(0x8000)
	RequestCodeProtected         = uint16(0x4000)
	RequestCodeProtectedReserved = RequestCodeReserved | RequestCodeProtected
)

user-defined request codes: unprotected from 0 to 2^14-1 protected from 2^16 - 2^14 - 1

View Source
const RequestIdSize = hashing.HashSize + 2

Variables

This section is empty.

Functions

func OutputValueOfColor

func OutputValueOfColor(tx *Transaction, addr address.Address, color balance.Color) int64

func ReadRequestId

func ReadRequestId(r io.Reader, reqid *RequestId) error

Types

type NewStateBlockParams

type NewStateBlockParams struct {
	Color      balance.Color
	StateIndex uint32
	StateHash  hashing.HashValue
	Timestamp  int64
}

type Properties

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

func (*Properties) IsOrigin

func (prop *Properties) IsOrigin() bool

func (*Properties) IsState

func (prop *Properties) IsState() bool

func (*Properties) MustStateAddress

func (prop *Properties) MustStateAddress() *address.Address

func (*Properties) MustStateColor

func (prop *Properties) MustStateColor() *balance.Color

func (*Properties) NumFreeMintedTokens

func (prop *Properties) NumFreeMintedTokens() int64

NumFreeMintedTokens return total minted tokens minus number of requests

func (*Properties) Sender

func (prop *Properties) Sender() *address.Address

type RequestBlock

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

func NewRequestBlock

func NewRequestBlock(addr address.Address, reqCode RequestCode) *RequestBlock

func (*RequestBlock) Address

func (req *RequestBlock) Address() address.Address

func (*RequestBlock) Args

func (req *RequestBlock) Args() kv.RCodec

func (*RequestBlock) Clone

func (req *RequestBlock) Clone() *RequestBlock

func (*RequestBlock) Read

func (req *RequestBlock) Read(r io.Reader) error

func (*RequestBlock) RequestCode

func (req *RequestBlock) RequestCode() RequestCode

func (*RequestBlock) SetArgs

func (req *RequestBlock) SetArgs(args kv.Map)

func (*RequestBlock) String

func (req *RequestBlock) String(reqId *RequestId) string

func (*RequestBlock) Timelock

func (req *RequestBlock) Timelock() uint32

func (*RequestBlock) WithTimelock

func (req *RequestBlock) WithTimelock(tl uint32) *RequestBlock

func (*RequestBlock) WithTimelockUntil

func (req *RequestBlock) WithTimelockUntil(deadline time.Time) *RequestBlock

func (*RequestBlock) Write

func (req *RequestBlock) Write(w io.Writer) error

type RequestCode

type RequestCode uint16

func (RequestCode) Bytes

func (rc RequestCode) Bytes() []byte

func (RequestCode) IsProtected

func (rc RequestCode) IsProtected() bool

func (RequestCode) IsReserved

func (rc RequestCode) IsReserved() bool

func (RequestCode) IsUserDefined

func (rc RequestCode) IsUserDefined() bool

func (RequestCode) String

func (rc RequestCode) String() string

type RequestId

type RequestId [RequestIdSize]byte

func NewRequestId

func NewRequestId(txid valuetransaction.ID, index uint16) (ret RequestId)

func NewRequestIdFromString

func NewRequestIdFromString(reqIdStr string) (ret RequestId, err error)

func RequestIdFromBase58

func RequestIdFromBase58(str58 string) (*RequestId, error)

func TakeRequestIds

func TakeRequestIds(lst []RequestRef) []RequestId

func (*RequestId) Bytes

func (rid *RequestId) Bytes() []byte

func (*RequestId) Index

func (rid *RequestId) Index() uint16

func (*RequestId) Read

func (rid *RequestId) Read(r io.Reader) error

func (*RequestId) Short

func (rid *RequestId) Short() string

func (*RequestId) String

func (rid *RequestId) String() string

func (*RequestId) ToBase58

func (rid *RequestId) ToBase58() string

func (*RequestId) TransactionId

func (rid *RequestId) TransactionId() *valuetransaction.ID

func (*RequestId) Write

func (rid *RequestId) Write(w io.Writer) error

type RequestRef

type RequestRef struct {
	Tx    *Transaction
	Index uint16
}

func (*RequestRef) IsAuthorised

func (ref *RequestRef) IsAuthorised(ownerAddr *address.Address) bool

request block is authorised if the containing transaction's inputs contain owner's address

func (*RequestRef) RequestBlock

func (ref *RequestRef) RequestBlock() *RequestBlock

func (*RequestRef) RequestId

func (ref *RequestRef) RequestId() *RequestId

func (*RequestRef) Sender

func (ref *RequestRef) Sender() *address.Address

type StateBlock

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

state block of the SC transaction. Represents SC state update previous state block can be determined by the chain transfer of the SC token in the UTXO part of the transaction

func NewStateBlock

func NewStateBlock(par NewStateBlockParams) *StateBlock

func (*StateBlock) Clone

func (sb *StateBlock) Clone() *StateBlock

func (*StateBlock) Color

func (sb *StateBlock) Color() balance.Color

func (*StateBlock) Read

func (sb *StateBlock) Read(r io.Reader) error

func (*StateBlock) StateHash

func (sb *StateBlock) StateHash() hashing.HashValue

func (*StateBlock) StateIndex

func (sb *StateBlock) StateIndex() uint32

func (*StateBlock) Timestamp

func (sb *StateBlock) Timestamp() int64

func (*StateBlock) WithStateParams

func (sb *StateBlock) WithStateParams(stateIndex uint32, h *hashing.HashValue, ts int64) *StateBlock

func (*StateBlock) Write

func (sb *StateBlock) Write(w io.Writer) error

type Transaction

type Transaction struct {
	*valuetransaction.Transaction
	// contains filtered or unexported fields
}

Smart contract transaction wraps value transaction the stateBlock and requestBlocks are parsed from the dataPayload of the value transaction

func NewTransaction

func NewTransaction(vtx *valuetransaction.Transaction, stateBlock *StateBlock, requestBlocks []*RequestBlock) (*Transaction, error)

creates new sc transaction. It is immutable, i.e. tx hash is stable

func ParseValueTransaction

func ParseValueTransaction(vtx *valuetransaction.Transaction) (*Transaction, error)

parses dataPayload. Error is returned only if pre-parsing succeeded and parsing failed usually this can happen only due to targeted attack or

func (*Transaction) MustProperties

func (tx *Transaction) MustProperties() *Properties

func (*Transaction) MustState

func (tx *Transaction) MustState() *StateBlock

func (*Transaction) NumRequestsToAddress

func (tx *Transaction) NumRequestsToAddress(addr *address.Address) int

func (*Transaction) OutputBalancesByAddress

func (tx *Transaction) OutputBalancesByAddress(addr *address.Address) ([]*balance.Balance, bool)

func (*Transaction) Properties

func (tx *Transaction) Properties() (*Properties, error)

return valid properties if sc transaction is semantically correct

func (*Transaction) Requests

func (tx *Transaction) Requests() []*RequestBlock

func (*Transaction) Sender

func (tx *Transaction) Sender() *address.Address

Sender returns first input address. It is the unique address, because ParseValueTransaction doesn't allow other options

func (*Transaction) State

func (tx *Transaction) State() (*StateBlock, bool)

func (*Transaction) String

func (tx *Transaction) String() string

func (*Transaction) ValidateBlocks

func (tx *Transaction) ValidateBlocks(addr *address.Address) (bool, error)

validates state block and requests and returns if it origin state (if not error) address is address of the SC

Directories

Path Synopsis
vtxbuilder
package to build value transaction
package to build value transaction

Jump to

Keyboard shortcuts

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