- Struct
TxContext
- Constants
- Function
sender
- Function
signer_
- Function
epoch
- Function
new_object
- Function
ids_created
- Function
derive_id
use 0x1::signer;
Information about the transaction currently being executed.
This cannot be constructed by a transaction--it is a privileged object created by
the VM and passed in to the entrypoint of the transaction as &mut TxContext
.
struct TxContext has drop
Fields
-
signer: signer
-
A
signer
wrapping the address of the user that signed the current transaction -
tx_hash: vector<u8>
- Hash of the current transaction
-
epoch: u64
- The current epoch number.
-
ids_created: u64
- Counter recording the number of fresh id's created while executing this transaction. Always 0 at the start of a transaction
Expected an tx hash of length 32, but found a different length
const EBadTxHashLength: u64 = 0;
Number of bytes in an tx hash (which will be the transaction digest)
const TX_HASH_LENGTH: u64 = 32;
Return the address of the user that signed the current transaction
public fun sender(self: &tx_context::TxContext): address
Implementation
public fun sender(self: &TxContext): address {
signer::address_of(&self.signer)
}
Return a signer
for the user that signed the current transaction
public fun signer_(self: &tx_context::TxContext): &signer
public fun epoch(self: &tx_context::TxContext): u64
Generate a new, globally unique object ID with version 0
public(friend) fun new_object(ctx: &mut tx_context::TxContext): address
Implementation
public(friend) fun new_object(ctx: &mut TxContext): address {
let ids_created = ctx.ids_created;
let id = derive_id(*&ctx.tx_hash, ids_created);
ctx.ids_created = ids_created + 1;
id
}
Return the number of id's created by the current transaction. Hidden for now, but may expose later
fun ids_created(self: &tx_context::TxContext): u64
Implementation
fun ids_created(self: &TxContext): u64 {
self.ids_created
}
Native function for deriving an ID via hash(tx_hash || ids_created)