_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q2800
Color.TriadicScheme
train
def TriadicScheme(self, angle=120, mode='ryb'): '''Return two colors forming a triad or a split complementary with this one. Parameters: :angle: The angle between the hues of the created colors. The default value makes a triad. :mode: Select which color wheel to use for the generation (ryb/rgb). Returns: A tuple of two grapefruit.Color forming a color triad with this one or a split complementary. >>> c1 = Color.NewFromHsl(30, 1, 0.5) >>> c2, c3 = c1.TriadicScheme(mode='rgb') >>> c2.hsl (150.0, 1, 0.5) >>> c3.hsl (270.0, 1, 0.5) >>> c2, c3 = c1.TriadicScheme(angle=40, mode='rgb') >>> c2.hsl (190.0, 1, 0.5)
python
{ "resource": "" }
q2801
Color.from_html
train
def from_html(cls, html_string): """ Create sRGB color from a web-color name or hexcode. :param str html_string: Web-color name or hexcode. :rtype: Color
python
{ "resource": "" }
q2802
Color.to
train
def to(self, space): """ Convert color to a different color space. :param str space: Name of the color space. :rtype: Color :returns: A new spectra.Color in the given color space. """ if space == self.space: return self
python
{ "resource": "" }
q2803
Color.blend
train
def blend(self, other, ratio=0.5): """ Blend this color with another color in the same color space. By default, blends the colors half-and-half (ratio: 0.5). :param Color other: The color to blend. :param float ratio: How much to blend (0 -> 1). :rtype: Color :returns: A new spectra.Color """ keep = 1.0 - ratio if not self.space == other.space:
python
{ "resource": "" }
q2804
Color.brighten
train
def brighten(self, amount=10): """ Brighten this color by `amount` luminance. Converts this color to the LCH color space, and then increases the `L` parameter by `amount`. :param float amount: Amount to increase the luminance. :rtype: Color
python
{ "resource": "" }
q2805
Scale.colorspace
train
def colorspace(self, space): """ Create a new scale in the given color space. :param str space: The new color space. :rtype: Scale :returns: A new color.Scale object. """
python
{ "resource": "" }
q2806
Scale.range
train
def range(self, count): """ Create a list of colors evenly spaced along this scale's domain. :param int count: The number of colors to return. :rtype: list :returns: A list of spectra.Color objects. """ if count <= 1:
python
{ "resource": "" }
q2807
sort_response
train
def sort_response(response: Dict[str, Any]) -> OrderedDict: """ Sort the keys in a JSON-RPC response object. This has no effect other than making it nicer to read. Useful in Python 3.5 only, dictionaries are already sorted in newer Python versions. Example:: >>> json.dumps(sort_response({'id': 2, 'result': 5, 'jsonrpc': '2.0'})) {"jsonrpc": "2.0", "result": 5, "id": 1} Args: response: Deserialized JSON-RPC response. Returns: The same response, sorted in an OrderedDict. """ root_order = ["jsonrpc", "result", "error", "id"] error_order =
python
{ "resource": "" }
q2808
parse_callable
train
def parse_callable(path: str) -> Iterator: """ ConfigParser converter. Calls the specified object, e.g. Option "id_generators.decimal" returns `id_generators.decimal()`. """ module = path[: path.rindex(".")]
python
{ "resource": "" }
q2809
random
train
def random(length: int = 8, chars: str = digits + ascii_lowercase) -> Iterator[str]: """ A random string. Not unique, but has around 1 in a million chance of collision (with the default 8 character length). e.g. 'fubui5e6' Args: length: Length of the random string.
python
{ "resource": "" }
q2810
get_response
train
def get_response(response: Dict[str, Any]) -> JSONRPCResponse: """ Converts a deserialized response into a JSONRPCResponse object. The dictionary be either an error or success response, never a notification. Args: response: Deserialized response dictionary. We can assume the response is valid
python
{ "resource": "" }
q2811
parse
train
def parse( response_text: str, *, batch: bool, validate_against_schema: bool = True ) -> Union[JSONRPCResponse, List[JSONRPCResponse]]: """ Parses response text, returning JSONRPCResponse objects. Args: response_text: JSON-RPC response string. batch: If the response_text is an empty string, this determines how to parse. validate_against_schema: Validate against the json-rpc schema. Returns: Either a JSONRPCResponse, or a list of them. Raises: json.JSONDecodeError: The response was not valid JSON. jsonschema.ValidationError: The response was not a valid JSON-RPC response object. """ # If the response is empty, we can't deserialize it; an empty string is valid # JSON-RPC, but not valid JSON. if not response_text: if batch: # An empty string is a valid response to a batch request, when there were # only notifications in the batch. return [] else: #
python
{ "resource": "" }
q2812
AsyncClient.send
train
async def send( self, request: Union[str, Dict, List], trim_log_values: bool = False, validate_against_schema: bool = True, **kwargs: Any ) -> Response: """ Async version of Client.send. """ # We need both the serialized and deserialized version of the request if isinstance(request, str): request_text = request request_deserialized = deserialize(request) else: request_text = serialize(request) request_deserialized = request batch = isinstance(request_deserialized, list) response_expected = batch or "id" in request_deserialized self.log_request(request_text, trim_log_values=trim_log_values) response = await self.send_message(
python
{ "resource": "" }
q2813
main
train
def main( context: click.core.Context, method: str, request_type: str, id: Any, send: str ) -> None: """ Create a JSON-RPC request. """ exit_status = 0 # Extract the jsonrpc arguments positional = [a for a in context.args if "=" not in a] named = {a.split("=")[0]: a.split("=")[1] for a in context.args if "=" in a} # Create the request if request_type == "notify": req = Notification(method, *positional, **named) else: req = Request(method, *positional, request_id=id, **named) # type: ignore # Sending? if send: client = HTTPClient(send) try:
python
{ "resource": "" }
q2814
sort_request
train
def sort_request(request: Dict[str, Any]) -> OrderedDict: """ Sort a JSON-RPC request dict. This has no effect other than making the request nicer to read. >>> json.dumps(sort_request( ... {'id': 2, 'params': [2, 3], 'method': 'add', 'jsonrpc': '2.0'})) '{"jsonrpc": "2.0", "method": "add", "params": [2, 3], "id": 2}' Args:
python
{ "resource": "" }
q2815
Client.basic_logging
train
def basic_logging(self) -> None: """ Call this on the client object to create log handlers to output request and response messages. """ # Request handler if len(request_log.handlers) == 0: request_handler = logging.StreamHandler() request_handler.setFormatter( logging.Formatter(fmt=self.DEFAULT_REQUEST_LOG_FORMAT) ) request_log.addHandler(request_handler) request_log.setLevel(logging.INFO) # Response handler if len(response_log.handlers) == 0:
python
{ "resource": "" }
q2816
Client.log_response
train
def log_response( self, response: Response, trim_log_values: bool = False, **kwargs: Any ) -> None: """ Log a response. Note this is different to log_request, in that it takes a Response object, not a
python
{ "resource": "" }
q2817
Client.notify
train
def notify( self, method_name: str, *args: Any, trim_log_values: Optional[bool] = None, validate_against_schema: Optional[bool] = None, **kwargs: Any ) -> Response: """ Send a JSON-RPC request, without expecting a response. Args: method_name: The remote procedure's method name. args: Positional arguments passed to the remote procedure. kwargs: Keyword arguments passed to the remote procedure. trim_log_values: Abbreviate the log entries of requests and responses.
python
{ "resource": "" }
q2818
Client.request
train
def request( self, method_name: str, *args: Any, trim_log_values: bool = False, validate_against_schema: bool = True, id_generator: Optional[Iterator] = None, **kwargs: Any ) -> Response: """ Send a request by passing the method and arguments. >>> client.request("cat", name="Yoko") <Response[1] Args: method_name: The remote procedure's method name. args: Positional arguments passed to the remote procedure. kwargs: Keyword arguments passed to the remote procedure. trim_log_values: Abbreviate the log entries of requests and responses.
python
{ "resource": "" }
q2819
Oep4.init
train
def init(self, acct: Account, payer_acct: Account, gas_limit: int, gas_price: int) -> str: """ This interface is used to call the TotalSupply method in ope4 that initialize smart contract parameter. :param acct: an Account class that used to sign the transaction. :param payer_acct: an Account class that used to pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: the hexadecimal transaction hash value. """
python
{ "resource": "" }
q2820
Oep4.get_total_supply
train
def get_total_supply(self) -> int: """ This interface is used to call the TotalSupply method in ope4 that return the total supply of the oep4 token. :return: the total supply of the oep4 token. """ func = InvokeFunction('totalSupply')
python
{ "resource": "" }
q2821
Oep4.balance_of
train
def balance_of(self, b58_address: str) -> int: """ This interface is used to call the BalanceOf method in ope4 that query the ope4 token balance of the given base58 encode address. :param b58_address: the base58 encode address. :return: the oep4 token balance of the base58 encode address. """ func = InvokeFunction('balanceOf') Oep4.__b58_address_check(b58_address)
python
{ "resource": "" }
q2822
Oep4.transfer
train
def transfer(self, from_acct: Account, b58_to_address: str, value: int, payer_acct: Account, gas_limit: int, gas_price: int) -> str: """ This interface is used to call the Transfer method in ope4 that transfer an amount of tokens from one account to another account. :param from_acct: an Account class that send the oep4 token. :param b58_to_address: a base58 encode address that receive the oep4 token. :param value: an int value that indicate the amount oep4 token that will be transferred in this transaction. :param payer_acct: an Account class that used to pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: the hexadecimal transaction hash value. """ func = InvokeFunction('transfer') if not isinstance(value, int): raise SDKException(ErrorCode.param_err('the data type of value should be int.')) if value < 0: raise SDKException(ErrorCode.param_err('the value should be equal or great than 0.')) if not isinstance(from_acct, Account): raise
python
{ "resource": "" }
q2823
Oep4.transfer_multi
train
def transfer_multi(self, transfer_list: list, payer_acct: Account, signers: list, gas_limit: int, gas_price: int): """ This interface is used to call the TransferMulti method in ope4 that allow transfer amount of token from multiple from-account to multiple to-account multiple times. :param transfer_list: a parameter list with each item contains three sub-items: base58 encode transaction sender address, base58 encode transaction receiver address, amount of token in transaction. :param payer_acct: an Account class that used to pay for the transaction. :param signers: a signer list used to sign this transaction which should contained all sender in args. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: the hexadecimal transaction hash value. """ func = InvokeFunction('transferMulti') for index, item in enumerate(transfer_list): Oep4.__b58_address_check(item[0]) Oep4.__b58_address_check(item[1]) if not isinstance(item[2], int): raise SDKException(ErrorCode.param_err('the data type of value should be int.')) if item[2] < 0: raise SDKException(ErrorCode.param_err('the value should be equal or great than 0.')) from_address_array = Address.b58decode(item[0]).to_bytes()
python
{ "resource": "" }
q2824
Oep4.approve
train
def approve(self, owner_acct: Account, b58_spender_address: str, amount: int, payer_acct: Account, gas_limit: int, gas_price: int): """ This interface is used to call the Approve method in ope4 that allows spender to withdraw a certain amount of oep4 token from owner account multiple times. If this function is called again, it will overwrite the current allowance with new value. :param owner_acct: an Account class that indicate the owner. :param b58_spender_address: a base58 encode address that be allowed to spend the oep4 token in owner's account. :param amount: an int value that indicate the amount oep4 token that will be transferred in this transaction. :param payer_acct: an Account class that used to pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: the hexadecimal transaction hash value. """ func = InvokeFunction('approve') if not isinstance(amount, int): raise SDKException(ErrorCode.param_err('the data type of amount should be int.')) if amount < 0:
python
{ "resource": "" }
q2825
Oep4.allowance
train
def allowance(self, b58_owner_address: str, b58_spender_address: str): """ This interface is used to call the Allowance method in ope4 that query the amount of spender still allowed to withdraw from owner account. :param b58_owner_address: a base58 encode address that represent owner's account. :param b58_spender_address: a base58 encode address that represent spender's account. :return: the amount of oep4 token that owner allow
python
{ "resource": "" }
q2826
Oep4.transfer_from
train
def transfer_from(self, spender_acct: Account, b58_from_address: str, b58_to_address: str, value: int, payer_acct: Account, gas_limit: int, gas_price: int): """ This interface is used to call the Allowance method in ope4 that allow spender to withdraw amount of oep4 token from from-account to to-account. :param spender_acct: an Account class that actually spend oep4 token. :param b58_from_address: an base58 encode address that actually pay oep4 token for the spender's spending. :param b58_to_address: a base58 encode address that receive the oep4 token. :param value: the amount of ope4 token in this transaction. :param payer_acct: an Account class that used to pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: the hexadecimal transaction hash value. """ func = InvokeFunction('transferFrom') Oep4.__b58_address_check(b58_from_address) Oep4.__b58_address_check(b58_to_address) if not isinstance(spender_acct, Account): raise SDKException(ErrorCode.param_err('the data type of spender_acct should be Account.')) spender_address_array = spender_acct.get_address().to_bytes() from_address_array = Address.b58decode(b58_from_address).to_bytes() to_address_array = Address.b58decode(b58_to_address).to_bytes() if not isinstance(value, int): raise SDKException(ErrorCode.param_err('the data type of value should be int.')) func.set_params_value(spender_address_array, from_address_array, to_address_array, value) params = func.create_invoke_code() unix_time_now = int(time.time())
python
{ "resource": "" }
q2827
WalletManager.import_identity
train
def import_identity(self, label: str, encrypted_pri_key: str, pwd: str, salt: str, b58_address: str) -> Identity: """ This interface is used to import identity by providing encrypted private key, password, salt and base58 encode address which should be correspond to the encrypted private key provided. :param label: a label for identity. :param encrypted_pri_key: an encrypted private key in base64 encoding from. :param pwd: a password which is used to encrypt and decrypt the private key. :param salt: a salt value which will be used in the process of encrypt private key. :param b58_address: a base58 encode address which correspond with the encrypted private key provided. :return: if succeed, an Identity object will be returned.
python
{ "resource": "" }
q2828
WalletManager.create_identity_from_private_key
train
def create_identity_from_private_key(self, label: str, pwd: str, private_key: str) -> Identity: """ This interface is used to create identity based on given label, password and private key. :param label: a label for identity. :param pwd: a password which will be used to encrypt and decrypt the private key. :param private_key: a private key
python
{ "resource": "" }
q2829
WalletManager.create_account
train
def create_account(self, pwd: str, label: str = '') -> Account: """ This interface is used to create account based on given password and label. :param label: a label for account. :param pwd: a password which will be used to encrypt and decrypt the private key
python
{ "resource": "" }
q2830
WalletManager.import_account
train
def import_account(self, label: str, encrypted_pri_key: str, pwd: str, b58_address: str, b64_salt: str, n: int = 16384) -> AccountData: """ This interface is used to import account by providing account data. :param label: str, wallet label :param encrypted_pri_key: str, an encrypted private key in base64 encoding from :param pwd: str, a password which is used to encrypt and decrypt the private key :param b58_address: str, a base58 encode wallet address value :param b64_salt: str, a base64 encode salt value which is used in the encryption of private key :param n: int, CPU/Memory cost parameter. It must be a power of 2 and less than :math:`2^{32}` :return: if succeed, return an data structure which contain the information of a wallet account.
python
{ "resource": "" }
q2831
WalletManager.create_account_from_private_key
train
def create_account_from_private_key(self, password: str, private_key: str, label: str = '') -> AccountData: """ This interface is used to create account by providing an encrypted private key and it's decrypt password. :param label: a label for account. :param password: a password which is used to decrypt the encrypted private key. :param private_key: a private key in the form of string. :return: if succeed, return an AccountData object. if failed, return a None object. """ salt = get_random_hex_str(16)
python
{ "resource": "" }
q2832
WalletManager.get_default_account_data
train
def get_default_account_data(self) -> AccountData: """ This interface is used to get the default account in WalletManager. :return: an AccountData object that contain all the information of a default account. """ for acct in self.wallet_in_mem.accounts: if not
python
{ "resource": "" }
q2833
AbiInfo.get_function
train
def get_function(self, name: str) -> AbiFunction or None: """ This interface is used to get an AbiFunction object from AbiInfo object by given function name. :param name: the function name in abi file :return: if succeed, an AbiFunction will constructed based on given function name """
python
{ "resource": "" }
q2834
RpcClient.get_version
train
def get_version(self, is_full: bool = False) -> dict or str: """ This interface is used to get the version information of the connected node in current network. Return: the version information of the connected node. """
python
{ "resource": "" }
q2835
RpcClient.get_connection_count
train
def get_connection_count(self, is_full: bool = False) -> int: """ This interface is used to get the current number of connections for the node in current network. Return: the number of connections. """
python
{ "resource": "" }
q2836
RpcClient.get_gas_price
train
def get_gas_price(self, is_full: bool = False) -> int or dict: """ This interface is used to get the gas price in current network. Return: the value of gas price. """ payload = self.generate_json_rpc_payload(RpcMethod.GET_GAS_PRICE)
python
{ "resource": "" }
q2837
RpcClient.get_network_id
train
def get_network_id(self, is_full: bool = False) -> int: """ This interface is used to get the network id of current network. Return: the network id
python
{ "resource": "" }
q2838
RpcClient.get_block_by_height
train
def get_block_by_height(self, height: int, is_full: bool = False) -> dict: """ This interface is used to get the block information by block height in current network. Return: the decimal total number of blocks in current network. """
python
{ "resource": "" }
q2839
RpcClient.get_block_count
train
def get_block_count(self, is_full: bool = False) -> int or dict: """ This interface is used to get the decimal block number in current network. Return: the decimal total number of blocks in current network.
python
{ "resource": "" }
q2840
RpcClient.get_block_height
train
def get_block_height(self, is_full: bool = False) -> int or dict: """ This interface is used to get the decimal block height in current network. Return: the decimal total height of blocks in current network. """
python
{ "resource": "" }
q2841
RpcClient.get_current_block_hash
train
def get_current_block_hash(self, is_full: bool = False) -> str: """ This interface is used to get the hexadecimal hash value of the highest block in current network. Return: the hexadecimal hash value of the highest block in current network. """
python
{ "resource": "" }
q2842
RpcClient.get_balance
train
def get_balance(self, b58_address: str, is_full: bool = False) -> dict: """ This interface is used to get the account balance of specified base58 encoded address in current network. :param b58_address: a base58 encoded account address. :param is_full: :return: the value of account balance in dictionary form.
python
{ "resource": "" }
q2843
RpcClient.get_allowance
train
def get_allowance(self, asset_name: str, from_address: str, to_address: str, is_full: bool = False) -> str: """ This interface is used to get the the allowance from transfer-from account to transfer-to account in current network. :param asset_name: :param from_address: a base58 encoded account
python
{ "resource": "" }
q2844
RpcClient.get_storage
train
def get_storage(self, hex_contract_address: str, hex_key: str, is_full: bool = False) -> str: """ This interface is used to get the corresponding stored value based on hexadecimal contract address and stored key. :param hex_contract_address: hexadecimal contract address. :param hex_key: a hexadecimal stored key. :param is_full: :return:
python
{ "resource": "" }
q2845
RpcClient.get_transaction_by_tx_hash
train
def get_transaction_by_tx_hash(self, tx_hash: str, is_full: bool = False) -> dict: """ This interface is used to get the corresponding transaction information based on the specified hash value. :param tx_hash: str, a hexadecimal hash value. :param is_full: :return: dict """
python
{ "resource": "" }
q2846
RpcClient.get_smart_contract
train
def get_smart_contract(self, hex_contract_address: str, is_full: bool = False) -> dict: """ This interface is used to get the information of smart contract based on the specified hexadecimal hash value. :param hex_contract_address: str, a hexadecimal hash value. :param is_full: :return: the information of smart contract in dictionary form.
python
{ "resource": "" }
q2847
RpcClient.get_merkle_proof
train
def get_merkle_proof(self, tx_hash: str, is_full: bool = False) -> dict: """ This interface is used to get the corresponding merkle proof based on the specified hexadecimal hash value. :param tx_hash: an hexadecimal transaction hash value. :param is_full: :return: the merkle proof in dictionary form.
python
{ "resource": "" }
q2848
OntId.parse_ddo
train
def parse_ddo(ont_id: str, serialized_ddo: str or bytes) -> dict: """ This interface is used to deserialize a hexadecimal string into a DDO object in the from of dict. :param ont_id: the unique ID for identity. :param serialized_ddo: an serialized description object of ONT ID in form of str or bytes. :return: a description object of ONT ID in the from of dict. """ if len(serialized_ddo) == 0: return dict() if isinstance(serialized_ddo, str): stream = StreamManager.get_stream(bytearray.fromhex(serialized_ddo)) elif isinstance(serialized_ddo, bytes): stream = StreamManager.get_stream(serialized_ddo) else: raise SDKException(ErrorCode.params_type_error('bytes or str parameter is required.')) reader = BinaryReader(stream) try: public_key_bytes = reader.read_var_bytes() except SDKException: public_key_bytes = b'' try: attribute_bytes = reader.read_var_bytes() except SDKException: attribute_bytes = b''
python
{ "resource": "" }
q2849
OntId.get_ddo
train
def get_ddo(self, ont_id: str) -> dict: """ This interface is used to get a DDO object in the from of dict. :param ont_id: the unique ID for identity. :return: a description object of ONT ID in the from of dict. """ args = dict(ontid=ont_id.encode('utf-8')) invoke_code = build_vm.build_native_invoke_code(self.__contract_address, self.__version, 'getDDO', args) unix_time_now = int(time()) tx = Transaction(0,
python
{ "resource": "" }
q2850
OntId.registry_ont_id
train
def registry_ont_id(self, ont_id: str, ctrl_acct: Account, payer: Account, gas_limit: int, gas_price: int): """ This interface is used to send a Transaction object which is used to registry ontid. :param ont_id: OntId. :param ctrl_acct: an Account object which indicate who will sign for the transaction. :param payer: an Account object which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a hexadecimal transaction hash value. """ if not isinstance(ctrl_acct, Account) or not isinstance(payer, Account):
python
{ "resource": "" }
q2851
OntId.add_attribute
train
def add_attribute(self, ont_id: str, ctrl_acct: Account, attributes: Attribute, payer: Account, gas_limit: int, gas_price: int) -> str: """ This interface is used to send a Transaction object which is used to add attribute. :param ont_id: OntId. :param ctrl_acct: an Account object which indicate who will sign for the transaction. :param attributes: a list of attributes we want to add. :param payer: an Account object which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a hexadecimal transaction hash value. """ if not
python
{ "resource": "" }
q2852
OntId.remove_attribute
train
def remove_attribute(self, ont_id: str, operator: Account, attrib_key: str, payer: Account, gas_limit: int, gas_price: int): """ This interface is used to send a Transaction object which is used to remove attribute. :param ont_id: OntId. :param operator: an Account object which indicate who will sign for the transaction. :param attrib_key: a string which is used to indicate which attribute we want to remove. :param payer: an Account object which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a hexadecimal transaction
python
{ "resource": "" }
q2853
OntId.add_recovery
train
def add_recovery(self, ont_id: str, ctrl_acct: Account, b58_recovery_address: str, payer: Account, gas_limit: int, gas_price: int): """ This interface is used to send a Transaction object which is used to add the recovery. :param ont_id: OntId. :param ctrl_acct: an Account object which indicate who will sign for the transaction. :param b58_recovery_address: a base58 encode address which indicate who is the recovery. :param payer: an Account object which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a Transaction object which is used to add the recovery.
python
{ "resource": "" }
q2854
OntId.new_registry_ont_id_transaction
train
def new_registry_ont_id_transaction(self, ont_id: str, pub_key: str or bytes, b58_payer_address: str, gas_limit: int, gas_price: int) -> Transaction: """ This interface is used to generate a Transaction object which is used to register ONT ID. :param ont_id: OntId. :param pub_key: the hexadecimal public key in the form of string. :param b58_payer_address: a base58 encode address which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a Transaction object which is used to register ONT ID. """
python
{ "resource": "" }
q2855
OntId.new_revoke_public_key_transaction
train
def new_revoke_public_key_transaction(self, ont_id: str, bytes_operator: bytes, revoked_pub_key: str or bytes, b58_payer_address: str, gas_limit: int, gas_price: int): """ This interface is used to generate a Transaction object which is used to remove public key. :param ont_id: OntId. :param bytes_operator: operator args in from of bytes. :param revoked_pub_key: a public key string which will be removed. :param b58_payer_address: a base58 encode address which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a Transaction object which is used to remove public key. """
python
{ "resource": "" }
q2856
OntId.new_add_attribute_transaction
train
def new_add_attribute_transaction(self, ont_id: str, pub_key: str or bytes, attributes: Attribute, b58_payer_address: str, gas_limit: int, gas_price: int): """ This interface is used to generate a Transaction object which is used to add attribute. :param ont_id: OntId. :param pub_key: the hexadecimal public key in the form of string. :param attributes: a list of attributes we want to add. :param b58_payer_address: a base58 encode address which indicate who will pay for the transaction.
python
{ "resource": "" }
q2857
OntId.new_remove_attribute_transaction
train
def new_remove_attribute_transaction(self, ont_id: str, pub_key: str or bytes, attrib_key: str, b58_payer_address: str, gas_limit: int, gas_price: int): """ This interface is used to generate a Transaction object which is used to remove attribute. :param ont_id: OntId. :param pub_key: the hexadecimal public key in the form of string. :param attrib_key: a string which is used to indicate which attribute we want to remove. :param b58_payer_address: a base58 encode address which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a Transaction object which is used to remove attribute.
python
{ "resource": "" }
q2858
OntId.new_add_recovery_transaction
train
def new_add_recovery_transaction(self, ont_id: str, pub_key: str or bytes, b58_recovery_address: str, b58_payer_address: str, gas_limit: int, gas_price: int): """ This interface is used to generate a Transaction object which is used to add the recovery. :param ont_id: OntId. :param pub_key: the hexadecimal public key in the form of string. :param b58_recovery_address: a base58 encode address which indicate who is the recovery. :param b58_payer_address: a base58 encode address which indicate who will pay for
python
{ "resource": "" }
q2859
Transaction.sign_transaction
train
def sign_transaction(self, signer: Account): """ This interface is used to sign the transaction. :param signer: an Account object which will sign the transaction. :return: a Transaction object which has been signed. """ tx_hash = self.hash256()
python
{ "resource": "" }
q2860
Transaction.add_sign_transaction
train
def add_sign_transaction(self, signer: Account): """ This interface is used to add signature into the transaction. :param signer: an Account object which will sign the transaction. :return: a Transaction object which has been signed. """ if self.sig_list is None or len(self.sig_list) == 0: self.sig_list = [] elif len(self.sig_list) >= TX_MAX_SIG_SIZE:
python
{ "resource": "" }
q2861
Transaction.add_multi_sign_transaction
train
def add_multi_sign_transaction(self, m: int, pub_keys: List[bytes] or List[str], signer: Account): """ This interface is used to generate an Transaction object which has multi signature. :param tx: a Transaction object which will be signed. :param m: the amount of signer. :param pub_keys: a list of public keys. :param signer: an Account object which will sign the transaction. :return: a Transaction object which has been signed. """ for index, pk in enumerate(pub_keys): if isinstance(pk, str): pub_keys[index] = pk.encode('ascii') pub_keys = ProgramBuilder.sort_public_keys(pub_keys)
python
{ "resource": "" }
q2862
Account.export_gcm_encrypted_private_key
train
def export_gcm_encrypted_private_key(self, password: str, salt: str, n: int = 16384) -> str: """ This interface is used to export an AES algorithm encrypted private key with the mode of GCM. :param password: the secret pass phrase to generate the keys from. :param salt: A string to use for better protection from dictionary attacks. This value does not need to be kept secret, but it should be randomly chosen for each derivation. It is recommended to be at least 8 bytes
python
{ "resource": "" }
q2863
Account.get_gcm_decoded_private_key
train
def get_gcm_decoded_private_key(encrypted_key_str: str, password: str, b58_address: str, salt: str, n: int, scheme: SignatureScheme) -> str: """ This interface is used to decrypt an private key which has been encrypted. :param encrypted_key_str: an gcm encrypted private key in the form of string. :param password: the secret pass phrase to generate the keys from. :param b58_address: a base58 encode address which should be correspond with the private key. :param salt: a string to use for better protection from dictionary attacks. :param n: CPU/memory cost parameter. :param scheme: the signature scheme. :return: a private key in the form of string. """ r = 8 p = 8 dk_len = 64 scrypt = Scrypt(n, r, p, dk_len) derived_key = scrypt.generate_kd(password, salt) iv = derived_key[0:12] key = derived_key[32:64] encrypted_key = base64.b64decode(encrypted_key_str).hex() mac_tag = bytes.fromhex(encrypted_key[64:96])
python
{ "resource": "" }
q2864
Account.export_wif
train
def export_wif(self) -> str: """ This interface is used to get export ECDSA private key in the form of WIF which is a way to encoding an ECDSA private key and make it easier to copy. :return: a WIF encode private key. """ data
python
{ "resource": "" }
q2865
Account.get_private_key_from_wif
train
def get_private_key_from_wif(wif: str) -> bytes: """ This interface is used to decode a WIF encode ECDSA private key. :param wif: a WIF encode private key. :return: a ECDSA private key in the form of bytes. """ if wif is None or wif is
python
{ "resource": "" }
q2866
pbkdf2
train
def pbkdf2(seed: str or bytes, dk_len: int) -> bytes: """ Derive one key from a seed. :param seed: the secret pass phrase to generate the keys from. :param dk_len: the length in bytes of every derived key. :return: """ key = b'' index = 1 bytes_seed =
python
{ "resource": "" }
q2867
AbiFunction.set_params_value
train
def set_params_value(self, *params): """ This interface is used to set parameter value for an function in abi file. """ if len(params) != len(self.parameters): raise Exception("parameter error") temp = self.parameters self.parameters =
python
{ "resource": "" }
q2868
AbiFunction.get_parameter
train
def get_parameter(self, param_name: str) -> Parameter: """ This interface is used to get a Parameter object from an AbiFunction object which contain given function parameter's name, type and value. :param param_name: a string
python
{ "resource": "" }
q2869
BinaryReader.read_bytes
train
def read_bytes(self, length) -> bytes: """ Read the specified number of bytes from the stream. Args: length (int): number of bytes to read. Returns:
python
{ "resource": "" }
q2870
BinaryReader.read_float
train
def read_float(self, little_endian=True): """ Read 4 bytes as a float value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: float:
python
{ "resource": "" }
q2871
BinaryReader.read_double
train
def read_double(self, little_endian=True): """ Read 8 bytes as a double value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: float:
python
{ "resource": "" }
q2872
BinaryReader.read_int8
train
def read_int8(self, little_endian=True): """ Read 1 byte as a signed integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
python
{ "resource": "" }
q2873
BinaryReader.read_uint8
train
def read_uint8(self, little_endian=True): """ Read 1 byte as an unsigned integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
python
{ "resource": "" }
q2874
BinaryReader.read_int16
train
def read_int16(self, little_endian=True): """ Read 2 byte as a signed integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
python
{ "resource": "" }
q2875
BinaryReader.read_uint16
train
def read_uint16(self, little_endian=True): """ Read 2 byte as an unsigned integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
python
{ "resource": "" }
q2876
BinaryReader.read_int32
train
def read_int32(self, little_endian=True): """ Read 4 bytes as a signed integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
python
{ "resource": "" }
q2877
BinaryReader.read_uint32
train
def read_uint32(self, little_endian=True): """ Read 4 bytes as an unsigned integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
python
{ "resource": "" }
q2878
BinaryReader.read_int64
train
def read_int64(self, little_endian=True): """ Read 8 bytes as a signed integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
python
{ "resource": "" }
q2879
BinaryReader.read_uint64
train
def read_uint64(self, little_endian=True): """ Read 8 bytes as an unsigned integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
python
{ "resource": "" }
q2880
BinaryReader.read_var_bytes
train
def read_var_bytes(self, max_size=sys.maxsize) -> bytes: """ Read a variable length of bytes from the stream. Args: max_size (int): (Optional) maximum number of bytes to read. Returns:
python
{ "resource": "" }
q2881
BinaryWriter.write_byte
train
def write_byte(self, value): """ Write a single byte to the stream. Args: value (bytes, str or int): value to write to the stream. """ if isinstance(value, bytes): self.stream.write(value)
python
{ "resource": "" }
q2882
BinaryWriter.write_float
train
def write_float(self, value, little_endian=True): """ Pack the value as a float and write 4 bytes to the stream. Args: value (number): the value to write to the stream. little_endian (bool): specify the endianness. (Default) Little endian. Returns:
python
{ "resource": "" }
q2883
BinaryWriter.write_double
train
def write_double(self, value, little_endian=True): """ Pack the value as a double and write 8 bytes to the stream. Args: value (number): the value to write to the stream. little_endian (bool): specify the endianness. (Default) Little endian. Returns:
python
{ "resource": "" }
q2884
BinaryWriter.write_int8
train
def write_int8(self, value, little_endian=True): """ Pack the value as a signed byte and write 1 byte to the stream. Args: value: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
python
{ "resource": "" }
q2885
BinaryWriter.write_uint8
train
def write_uint8(self, value, little_endian=True): """ Pack the value as an unsigned byte and write 1 byte to the stream. Args: value: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
python
{ "resource": "" }
q2886
BinaryWriter.write_int16
train
def write_int16(self, value, little_endian=True): """ Pack the value as a signed integer and write 2 bytes to the stream. Args: value: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
python
{ "resource": "" }
q2887
BinaryWriter.write_uint16
train
def write_uint16(self, value, little_endian=True): """ Pack the value as an unsigned integer and write 2 bytes to the stream. Args: value: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
python
{ "resource": "" }
q2888
BinaryWriter.write_int32
train
def write_int32(self, value, little_endian=True): """ Pack the value as a signed integer and write 4 bytes to the stream. Args: value: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
python
{ "resource": "" }
q2889
BinaryWriter.write_uint32
train
def write_uint32(self, value, little_endian=True): """ Pack the value as an unsigned integer and write 4 bytes to the stream. Args: value: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
python
{ "resource": "" }
q2890
BinaryWriter.write_int64
train
def write_int64(self, value, little_endian=True): """ Pack the value as a signed integer and write 8 bytes to the stream. Args: value: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
python
{ "resource": "" }
q2891
BinaryWriter.write_uint64
train
def write_uint64(self, value, little_endian=True): """ Pack the value as an unsigned integer and write 8 bytes to the stream. Args: value: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
python
{ "resource": "" }
q2892
Asset.get_asset_address
train
def get_asset_address(self, asset: str) -> bytes: """ This interface is used to get the smart contract address of ONT otr ONG. :param asset: a string which is used to indicate which asset's contract address we want to get. :return: the contract address of asset in the form of bytearray. """
python
{ "resource": "" }
q2893
Asset.query_balance
train
def query_balance(self, asset: str, b58_address: str) -> int: """ This interface is used to query the account's ONT or ONG balance. :param asset: a string which is used to indicate which asset we want to check the balance. :param b58_address: a base58 encode account address. :return: account balance. """ raw_address = Address.b58decode(b58_address).to_bytes() contract_address = self.get_asset_address(asset) invoke_code = build_native_invoke_code(contract_address, b'\x00', "balanceOf", raw_address)
python
{ "resource": "" }
q2894
Asset.query_unbound_ong
train
def query_unbound_ong(self, base58_address: str) -> int: """ This interface is used to query the amount of account's unbound ong. :param base58_address: a base58 encode address which indicate which account's unbound ong we want to query. :return: the amount of unbound ong in the form of int. """
python
{ "resource": "" }
q2895
Asset.query_symbol
train
def query_symbol(self, asset: str) -> str: """ This interface is used to query the asset's symbol of ONT or ONG. :param asset: a string which is used to indicate which asset's symbol we want to get. :return: asset's symbol in the form of string. """ contract_address = self.get_asset_address(asset) method = 'symbol' invoke_code = build_native_invoke_code(contract_address, b'\x00', method, bytearray())
python
{ "resource": "" }
q2896
Asset.query_decimals
train
def query_decimals(self, asset: str) -> int: """ This interface is used to query the asset's decimals of ONT or ONG. :param asset: a string which is used to indicate which asset's decimals we want to get :return: asset's decimals in the form of int """ contract_address = self.get_asset_address(asset)
python
{ "resource": "" }
q2897
Asset.new_transfer_transaction
train
def new_transfer_transaction(self, asset: str, b58_from_address: str, b58_to_address: str, amount: int, b58_payer_address: str, gas_limit: int, gas_price: int) -> Transaction: """ This interface is used to generate a Transaction object for transfer. :param asset: a string which is used to indicate which asset we want to transfer. :param b58_from_address: a base58 encode address which indicate where the asset from. :param b58_to_address: a base58 encode address which indicate where the asset to. :param amount: the amount of asset that will be transferred. :param b58_payer_address: a base58 encode address which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a Transaction object which can be used for transfer. """ if not isinstance(b58_from_address, str) or not isinstance(b58_to_address, str) or not isinstance( b58_payer_address, str): raise SDKException(ErrorCode.param_err('the data type of base58 encode address should be the string.')) if len(b58_from_address) != 34 or len(b58_to_address) != 34 or len(b58_payer_address) != 34: raise SDKException(ErrorCode.param_err('the length of base58 encode address should be 34 bytes.')) if amount <= 0: raise SDKException(ErrorCode.other_error('the amount should be greater than than zero.'))
python
{ "resource": "" }
q2898
Asset.new_approve_transaction
train
def new_approve_transaction(self, asset: str, b58_send_address: str, b58_recv_address: str, amount: int, b58_payer_address: str, gas_limit: int, gas_price: int) -> Transaction: """ This interface is used to generate a Transaction object for approve. :param asset: a string which is used to indicate which asset we want to approve. :param b58_send_address: a base58 encode address which indicate where the approve from. :param b58_recv_address: a base58 encode address which indicate where the approve to. :param amount: the amount of asset that will be approved. :param b58_payer_address: a base58 encode address which indicate who will pay for the transaction. :param gas_limit: an int value that indicate the gas limit. :param gas_price: an int value that indicate the gas price. :return: a Transaction object which can be used for approve. """ if not isinstance(b58_send_address, str) or not isinstance(b58_recv_address, str): raise SDKException(ErrorCode.param_err('the data type of base58 encode address should be the string.')) if len(b58_send_address) != 34 or len(b58_recv_address) != 34: raise SDKException(ErrorCode.param_err('the length of base58 encode address should be 34 bytes.')) if amount <= 0: raise SDKException(ErrorCode.other_error('the amount should be greater than than zero.')) if gas_price < 0:
python
{ "resource": "" }
q2899
Asset.new_transfer_from_transaction
train
def new_transfer_from_transaction(self, asset: str, b58_send_address: str, b58_from_address: str, b58_recv_address: str, amount: int, b58_payer_address: str, gas_limit: int, gas_price: int) -> Transaction: """ This interface is used to generate a Transaction object that allow one account to transfer a amount of ONT or ONG Asset to another account, in the condition of the first account had been approved. :param asset: a string which is used to indicate which asset we want to transfer. :param b58_send_address: a base58 encode address which indicate where the asset from. :param b58_from_address: a base58 encode address which indicate where the asset from.
python
{ "resource": "" }