Building and parsing operations¶
Operation group¶
-
class
pytezos.operation.group.
OperationGroup
(context: pytezos.context.impl.ExecutionContext, contents: Optional[List[Dict[str, Any]]] = None, protocol: Optional[str] = None, chain_id: Optional[int] = None, branch: Optional[str] = None, signature: Optional[str] = None)[source]¶ Operation group representation: contents (single or multiple), signature, other fields, and also useful helpers for filling with precise fees, signing, forging, and injecting.
-
activate_account
(activation_code='', pkh='')¶ Activate recommended allocations for contributions to the TF fundraiser. More info https://activate.tezos.com/
- Parameters
activation_code – Secret code from pdf, leave empty for autocomplete
pkh – Public key hash, leave empty for autocomplete
- Returns
dict or OperationGroup
-
autofill
(gas_reserve: int = 100, counter: Optional[int] = None, branch_offset: int = 50, fee: Optional[int] = None, gas_limit: Optional[int] = None, storage_limit: Optional[int] = None) → pytezos.operation.group.OperationGroup[source]¶ Fill the gaps and then simulate the operation in order to calculate fee, gas/storage limits.
- Parameters
gas_reserve – Add a safe reserve for dynamically calculated gas limit (default is 100).
counter – Override counter value (for manual handling)
branch_offset – Select head~offset block as branch, where offset is in range (0, 60)
fee – Explicitly set fee for operation. If not set fee will be calculated depeding on results of operation dry-run.
gas_limit – Explicitly set gas limit for operation. If not set gas limit will be calculated depeding on results of operation dry-run.
storage_limit – Explicitly set storage limit for operation. If not set storage limit will be calculated depeding on results of operation dry-run.
- Return type
-
ballot
(proposal, ballot, source='', period=0)¶ Vote for a proposal in a given voting period. Can only be submitted during Testing_vote or Promotion_vote periods, and only once per period. More info https://tezos.gitlab.io/master/whitedoc/voting.html
- Parameters
proposal – Hash of the proposal
ballot – ‘Yay’, ‘Nay’ or ‘Pass’
source – Public key hash (of the signatory), leave None for autocomplete
period – Number of the current voting period, leave None for autocomplete
- Returns
dict or OperationGroup
-
delegation
(delegate='', source='', counter=0, fee=0, gas_limit=0, storage_limit=0)¶ Delegate funds or register yourself as a delegate.
- Parameters
delegate – tz address of delegate, leave None to register yourself as a delegate
source – Address from which funds will be delegated, leave None to use signatory address
counter – Current account counter, leave None for autocomplete
fee – Leave None for autocomplete
gas_limit – Leave None for autocomplete
storage_limit – Leave None for autocomplete
- Returns
dict or OperationGroup
-
double_baking_evidence
(bh1, bh2)¶ Provide evidence of double baking (two different blocks at the same height).
- Parameters
bh1 – First block hash
bh2 – Second block hash
- Returns
dict or OperationGroup
-
double_endorsement_evidence
(op1: dict, op2: dict)¶ Provide evidence of double endorsement (endorsing two different blocks at the same block height).
- Parameters
op1 –
Inline endorsement {
”branch”: $block_hash, “operations”: {
”kind”: “endorsement”, “level”: integer ∈ [-2^31-2, 2^31+2]
}, “signature”?: $Signature
}
op2 – Inline endorsement
- Returns
dict or OperationGroup
-
endorsement
(level: int)¶ Endorse a block.
- Parameters
level – Endorsed level
- Returns
dict or OperationGroup
-
fill
(counter=None, branch_offset=50)[source]¶ Try to fill all fields left unfilled, use approximate fees (not optimal, use autofill to simulate operation and get precise values).
- Parameters
counter – Override counter value (for manual handling)
branch_offset – select head~offset block as branch, where offset is in range (0, 60)
- Return type
-
forge
(validate=True)[source]¶ Convert json representation of the operation group into bytes.
- Parameters
validate – Forge remotely also and compare results, default is True
- Returns
Hex string
-
inject
(_async=True, preapply=True, check_result=True, num_blocks_wait=5, time_between_blocks: Optional[int] = None)[source]¶ Inject the signed operation group.
- Parameters
_async – do not wait for operation inclusion (default is True)
preapply – do a preapply before injection
check_result – raise RpcError in case operation is applied but has runtime errors
num_blocks_wait – number of blocks to wait for injection
time_between_blocks – override the corresponding parameter from constants
- Returns
operation group with metadata (raw RPC response)
-
operation
(content)[source]¶ Create new operation group with extra content added.
- Parameters
content – Kind-specific operation body
- Return type
-
origination
(script, balance=0, delegate=None, source='', counter=0, fee=0, gas_limit=0, storage_limit=0)¶ Deploy smart contract (scriptless KT accounts are not used for delegation since Babylon)
- Parameters
script – {“code”: $Micheline, “storage”: $Micheline}
balance – Amount transferred on the balance, WARNING: there is no default way to withdraw funds. More info: https://tezos.stackexchange.com/questions/1315/can-i-withdraw-funds-from-an-empty-smart-contract
delegate – Set contract delegate, default None
source – Address from which funds will be sent, leave None to use signatory address
counter – Current account counter, leave None for autocomplete
fee – Leave None for autocomplete
gas_limit – Leave None for autocomplete
storage_limit – Leave None for autocomplete
- Returns
dict or OperationGroup
-
proposals
(proposals, source='', period=0)¶ Submit and/or upvote proposals to amend the protocol. Can only be submitted during a proposal period. More info https://tezos.gitlab.io/master/whitedoc/voting.html
- Parameters
proposals – List of proposal hashes or single proposal hash
source – Public key hash (of the signatory), leave None for autocomplete
period – Number of the current voting period, leave 0 for autocomplete
- Returns
dict or OperationGroup
-
result
() → List[pytezos.operation.result.OperationResult][source]¶ Parse the preapply result.
- Return type
List[OperationResult]
-
reveal
(public_key='', source='', counter=0, fee=0, gas_limit=0, storage_limit=0)¶ Reveal the public key associated with a tz address.
- Parameters
public_key – Public key to reveal, Base58 encoded
source – Public key hash of the key revealed, leave None to use signatory address
counter – Current account counter, leave None for autocomplete (More info https://tezos.stackexchange.com/questions/632/how-counter-grows)
fee – Leave None for autocomplete
gas_limit – Leave None for autocomplete
storage_limit – Leave None for autocomplete
- Returns
dict or OperationGroup
-
run
(block_id='head')[source]¶ Simulate operation without signature checks.
- Parameters
block_id – Specify a level at which this operation should be applied (default is head)
- Returns
RPC response from run_operation
-
seed_nonce_revelation
(level: int, nonce)¶ Reveal the nonce committed operation in the previous cycle. More info https://tezos.stackexchange.com/questions/567/what-are-nonce-revelations
- Parameters
level – When nonce hash was committed
nonce – Hex string
- Returns
dict or OperationGroup
-
transaction
(destination, amount=0, parameters=None, source='', counter=0, fee=0, gas_limit=0, storage_limit=0)¶ Transfer tez to a given address (implicit or originated). If the receiver is a smart contract, then optional parameters may be passed.
- Parameters
source – Address from which funds will be sent, leave None to use signatory address
destination – Address
amount – Amount to send in microtez (int) or tez (Decimal) (optional)
counter – Current account counter, leave None for autocomplete
parameters – { “entrypoint”: $string, “value”: $Micheline expression } (optional)
fee – Leave None for autocomplete
gas_limit – Leave None for autocomplete
storage_limit – Leave None for autocomplete
- Returns
dict or OperationGroup
-
Operation result¶
-
class
pytezos.operation.result.
OperationResult
(**props)[source]¶ Operation result representation + useful parsing helpers for operation group
-
static
burned
(operation_group) → int[source]¶ Get total burned (due to account allocations) for an operation group (recursively).
- Parameters
operation_group – {“branch”: “B…”, “contents”: […], …} OR a single content {“kind”: “transaction”, …}
-
static
consumed_gas
(operation_group) → int[source]¶ Get total consumed gas for an operation group (recursively).
- Parameters
operation_group – {“branch”: “B…”, “contents”: […], …} OR a single content {“kind”: “transaction”, …}
-
static
errors
(operation_group: dict) → list[source]¶ Collect errors from all operation results in a group.
- Parameters
operation_group – {“branch”: “B…”, “contents”: […], …} OR a single content {“kind”: “transaction”, …}
- Returns
list of errors [{“id”: “”, …}]
-
classmethod
from_operation_group
(operation_group: dict, **predicates) → List[pytezos.operation.result.OperationResult][source]¶ Initialize with operation group contents.
- Parameters
operation_group – operation_group: {“branch”: “B…”, “contents”: […], …} :param predicates: filter contents using predicates field=value
- Return type
List[OperationResult]
-
classmethod
from_origination
(content: dict)[source]¶ Initialize with origination content.
- Parameters
content –
- Return type
-
classmethod
from_transaction
(content: dict)[source]¶ Initialize with transaction content.
- Parameters
content –
- Return type
-
static
is_applied
(operation_group) → bool[source]¶ Check if ALL operations in a group are applied.
- Parameters
operation_group – {“branch”: “B…”, “contents”: […], …} OR a single content {“kind”: “transaction”, …}
-
static
iter_contents
(operation_group: dict)[source]¶ Lazily iterate operation group contents including internal operations.
- Parameters
operation_group – {“branch”: “B…”, “contents”: […], …} OR a single content {“kind”: “transaction”, …}
- Returns
generator
-
static
iter_results
(operation_group: dict)[source]¶ Lazily iterate operation results including internal operation results.
- Parameters
operation_group – {“branch”: “B…”, “contents”: […], …} OR a single content {“kind”: “transaction”, …}
- Returns
generator
-
static
Fees and limits¶
-
pytezos.operation.fees.
calculate_fee
(content: dict, consumed_gas: int, extra_size: int, reserve=10) → int[source]¶ Calculate minimal required operation fee.
- Parameters
content – operation content {…, “kind”: “transaction”, … }
consumed_gas – amount of gas consumed during the simulation (dry-run)
extra_size – size of the additional operation data (branch, etc)
reserve – safe reserve, just in case
-
pytezos.operation.fees.
default_fee
(content) → int[source]¶ Take hard gas limit instead of precise amount (no simulation) and calculate fee.
- Parameters
content – operation content {…, “kind”: “transaction”, … }
Local forge¶
-
pytezos.operation.forge.
forge_entrypoint
(entrypoint) → bytes[source]¶ Encode Michelson contract entrypoint into the byte form.
- Parameters
entrypoint – string
-
pytezos.operation.forge.
forge_operation
(content) → bytes[source]¶ Forge operation content (locally).
- Parameters
content – {.., “kind”: “transaction”, …}