nectar.rc module
- class nectar.rc.RC(blockchain_instance: Any | None = None, **kwargs: Any)
Bases:
object- account_create_dict(account_create_dict: Dict[str, Any]) Dict[str, int]
Calc RC costs for account create
- account_update_dict(account_update_dict: Dict[str, Any]) Dict[str, int]
Calc RC costs for account update
- claim_account(tx_size: int = 300) Dict[str, int]
Claim account
- comment(tx_size: int = 1000, permlink_length: int = 10, parent_permlink_length: int = 10) Dict[str, int]
Calc RC for a comment
- comment_dict(comment_dict: Dict[str, Any]) Dict[str, int]
Calc RC costs for a comment dict object
Example for calculating RC costs
from nectar.rc import RC comment_dict = { "permlink": "test", "author": "thecrazygm", "body": "test", "parent_permlink": "", "parent_author": "", "title": "test", "json_metadata": {"foo": "bar"} } rc = RC() print(rc.comment_dict(comment_dict))
- create_claimed_account_dict(create_claimed_account_dict: Dict[str, Any]) Dict[str, int]
Calc RC costs for claimed account create
- custom_json(tx_size: int = 444, follow_id: bool = False) Dict[str, int]
- custom_json_dict(custom_json_dict: Dict[str, Any]) Dict[str, int]
Calc RC costs for a custom_json
Example for calculating RC costs
from nectar.rc import RC from collections import OrderedDict custom_json_dict = { "json": [ "reblog", OrderedDict([("account", "xeroc"), ("author", "chainsquad"), ("permlink", "streemian-com-to-open-its-doors-and-offer-a-20-discount") ]) ], "required_auths": [], "required_posting_auths": ["xeroc"], "id": "follow" } rc = RC() print(rc.custom_json_dict(custom_json_dict))
- delegate_from_pool(from_pool: str, to_account: str, max_rc: int) Dict[str, Any]
Set a slot to receive RC from a pool
- Parameters:
from_pool (str) – Pool to set the slot to
to_account (str) – Account on which we want to update the slot
max_rc (int) – max rc to delegate
- delegate_to_pool(username: str, to_pool: str, rc: int) Dict[str, Any]
Set a slot to receive RC from a pool
- Parameters:
username (str) – user delegating rc to the pool
to_pool (str) – Pool to delegate to
rc (int) – rc to delegate
- get_authority_byte_count(auth: Dict[str, Any]) int
- get_resource_count(tx_size: int, execution_time_count: int, state_bytes_count: int = 0, new_account_op_count: int = 0, market_op_count: int = 0) Dict[str, int]
Build and return a resource_count mapping for RC cost calculation.
- Parameters:
tx_size (int): Transaction size in bytes; used for history bytes and for market bytes when applicable. execution_time_count (int): Execution time units for the operation. state_bytes_count (int, optional): Additional state bytes contributed by the operation (default 0). new_account_op_count (int, optional): Number of new-account operations included (default 0). market_op_count (int, optional): If > 0, marks the transaction as a market operation and sets market bytes to tx_size (default 0).
- Returns:
- dict: A dictionary containing keys used by the RC pricing engine, including:
resource_history_bytes
resource_state_bytes
resource_new_accounts
resource_execution_time
resource_market_bytes (only present if market_op_count > 0)
- get_tx_size(op: Any | Operation | Dict[str, Any]) int
Estimate the serialized size (in bytes) of a signed transaction containing the given operation.
This constructs a dummy Signed_Transaction using fixed reference fields and a hard-coded private key, signs it on the “HIVE” chain, and returns the length of the resulting serialized transaction in bytes. The value is an estimate useful for RC sizing and does not represent a real broadcastable transaction.
- Parameters:
op: Operation or dict-like operation payload to include in the transaction.
- Returns:
int: Number of bytes in the serialized, signed transaction.
- set_slot_delegator(from_pool: str, to_account: str, to_slot: int, signer: str) Dict[str, Any]
Set a slot to receive RC from a pool
- Parameters:
from_pool (str) – Pool to set the slot to
to_account (str) – Account on which we want to update the slot
to_slot (int) – slot we want to set
signer (str) – Account who broadcast this
- transfer(tx_size: int = 290, market_op_count: int = 1) Dict[str, int]
Calc RC of a transfer
- transfer_dict(transfer_dict: Dict[str, Any]) Dict[str, int]
Calculate Resource Credit (RC) cost for a transfer operation represented as a dict.
The input dict must contain the fields required by a Transfer operation (for example: “from”, “to”, “amount”, “memo”). This function builds a Transfer operation, estimates the signed transaction size, marks the operation as a market operation (market_op_count=1), and returns the RC cost computed by the blockchain instance.
- Parameters:
transfer_dict (dict): Fields for a Transfer operation compatible with operations.Transfer.
- Returns:
dict: RC cost structure as returned by the blockchain’s get_rc_cost.
- vote(tx_size: int = 210) Dict[str, int]
Calc RC for a vote
- vote_dict(vote_dict: Dict[str, Any]) Dict[str, int]
Calc RC costs for a vote
Example for calculating RC costs
from nectar.rc import RC vote_dict = { "voter": "foobara", "author": "foobarc", "permlink": "foobard", "weight": 1000 } rc = RC() print(rc.vote_dict(vote_dict))