pub struct Transaction {
    pub this_block_number: u64,
    pub prev_block_hash: Sha256Hash,
    pub timestamp: u32,
    pub random_bytes: Sha256Hash,
    pub to_address: PublicAddress,
    pub from_address: PublicAddress,
    pub value: u64,
    pub transaction_hash: Sha256Hash,
    pub arguments: Vec<u8>,
}
Expand description

smart_contract::Transaction is a handle containing the parameters of the smart contract invocation (e.g., the ‘args’ string provided by the contract_caller, the previous block hash, etc.)

It also has methods attached (‘set’ & ‘get’) that allow smart contracts to maintain persistent, blockchained state.

From this point on, smart_contract::Transaction can be interchangeably known as “ParallelChain Mainnet Smart Contract Development Kit” or the “SDK” or “SC-SDK”.

Basic example

let tx: smart_contract::Transaction = Transaction::new();
 
assert!(tx.get("hello").is_none());
 
tx.Set("hello", "world");
assert_eq!(tx.get("hello")?, "world");

tx.Set("hello", "");
assert_eq!(tx.get("hello")?, "");

Fields

this_block_number: u64

Block Hash of this block

prev_block_hash: Sha256Hash

Block Hash of the previous block.

timestamp: u32

Unix timestamp

random_bytes: Sha256Hash

Reserved data

to_address: PublicAddress

Address of a recipient.

from_address: PublicAddress

Address of a sender.

value: u64

Amount of tokens to be sent to the smart contract address.

transaction_hash: Sha256Hash

Hash of a transaction’s signature. The transaction hashes of other transactions included in a block are used to obtain the Merkle root hash of a block.

arguments: Vec<u8>

Transaction data as arguments to this contract call

Implementations

Default constructor.

new should never fail if the ParallelChain Mainnet Fullnode is configured properly.

new expects arguments in the form of Vec.

get returns Some(value) if a non-empty string is stored with key in the world state.

If get fails, the smart contract terminates and the sets this invocation made are not committed.

set binds key to value in the world state.

return_value places value in the receipt of an ExternalToContract transaction. This method is not required when contract_init macro is being used on the actions() entrypoint function.

get input arguments for entrypoint

calling function which handled by blockchain executor It returns Option of Vec of bytes. Interpretation on the bytes depends on caller

view contract by accessing view entrypoint of the contract

A call to contract. The caller should already know the data type of return value from the function call It returns Option of T where T is return value from the function. If data type T is different from the actual return value type of the function, None is returned.

pay() calls the raw_pay() that runs a ctoe call to transfer credit to another address. Return the remaining balance of the receiver’s account

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.