0x2::tx_context
TxContext
sender
digest
epoch
epoch_timestamp_ms
fresh_object_address
ids_created
derive_id
TxContext
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
sender: address
tx_hash: vector<u8>
epoch: u64
epoch_timestamp_ms: u64
ids_created: u64
sender
Return the address of the user that signed the current transaction
public fun sender(self: &tx_context::TxContext): address
digest
Return the transaction digest (hash of transaction inputs). Please do not use as a source of randomness.
public fun digest(self: &tx_context::TxContext): &vector<u8>
epoch
Return the current epoch
public fun epoch(self: &tx_context::TxContext): u64
epoch_timestamp_ms
Return the epoch start time as a unix timestamp in milliseconds.
public fun epoch_timestamp_ms(self: &tx_context::TxContext): u64
public fun epoch_timestamp_ms(self: &TxContext): u64 {
self.epoch_timestamp_ms
}
fresh_object_address
Create an address
that has not been used. As it is an object address, it will never
occur as the address for a user.
In other words, the generated address is a globally unique object ID.
public fun fresh_object_address(ctx: &mut tx_context::TxContext): address
public fun fresh_object_address(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
}
ids_created
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
fun ids_created(self: &TxContext): u64 {
self.ids_created
}
derive_id
Native function for deriving an ID via hash(tx_hash | ids_created) |
fun derive_id(tx_hash: vector<u8>, ids_created: u64): address