Struct pchain_sdk::Transaction
source · [−]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: u64Block Hash of this block
prev_block_hash: Sha256HashBlock Hash of the previous block.
timestamp: u32Unix timestamp
random_bytes: Sha256HashReserved data
to_address: PublicAddressAddress of a recipient.
from_address: PublicAddressAddress of a sender.
value: u64Amount of tokens to be sent to the smart contract address.
transaction_hash: Sha256HashHash 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
sourceimpl Transaction
impl Transaction
sourcepub fn new() -> Self
pub fn new() -> Self
Default constructor.
new should never fail if the ParallelChain Mainnet Fullnode
is configured properly.
new expects arguments in the form of Vec
sourcepub fn get(key: &[u8]) -> Option<Vec<u8>>
pub fn get(key: &[u8]) -> Option<Vec<u8>>
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.
sourcepub fn return_value(value: Vec<u8>)
pub fn return_value(value: Vec<u8>)
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.
sourcepub fn get_arguments() -> Vec<u8>
pub fn get_arguments() -> Vec<u8>
get input arguments for entrypoint
pub fn emit_event(topic: &[u8], value: &[u8])
sourcepub fn call_contract(
contract_address: PublicAddress,
method_name: &str,
arguments: Vec<u8>,
value: u64,
gas: u64
) -> Option<Vec<u8>>
pub fn call_contract(
contract_address: PublicAddress,
method_name: &str,
arguments: Vec<u8>,
value: u64,
gas: u64
) -> Option<Vec<u8>>
calling function which handled by blockchain executor It returns Option of Vec of bytes. Interpretation on the bytes depends on caller
sourcepub fn view_contract(
contract_address: PublicAddress,
method_name: &str,
arguments: Vec<u8>
) -> Option<Vec<u8>>
pub fn view_contract(
contract_address: PublicAddress,
method_name: &str,
arguments: Vec<u8>
) -> Option<Vec<u8>>
view contract by accessing view entrypoint of the contract
sourcepub fn call<T: BorshDeserialize>(
address: PublicAddress,
method_name: &str,
arguments: Vec<u8>,
value: u64,
gas: u64
) -> Option<T>
pub fn call<T: BorshDeserialize>(
address: PublicAddress,
method_name: &str,
arguments: Vec<u8>,
value: u64,
gas: u64
) -> Option<T>
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.
sourcepub fn pay(address: PublicAddress, value: u64) -> u64
pub fn pay(address: PublicAddress, value: u64) -> u64
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
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnwindSafe for Transaction
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more