コード例 #1
0
def _transfer(wallet, account_id: int, token_type: str, contract_addr: str=None, to: str=0, amount: int=0):
    """ Send icx or token with Smart wallet

    :param wallet:
    :param account_id: from account id
    :param token_type:
    :param contract_addr: if token, it needed
    :param to: from account id or wallet address
    :param amount: amount to transfer
    :return:
    """

    params = {"account_id": convert_int_to_hex_str(account_id), "token_type": token_type,
              "contract_addr": contract_addr,
              "to": to,
              "amount": convert_int_to_hex_str(amount)}

    transaction = CallTransactionBuilder()\
        .from_(wallet.get_address())\
        .to(IconServiceContainer.contract_addr)\
        .step_limit(100000000000000)\
        .nid(3)\
        .nonce(2) \
        .method("transfer") \
        .params(params) \
        .build()

    result = _send_transaction(transaction, wallet, 9)
    for log in result['eventLogs']:
        if log['indexed'] == ['Pending(str)']:
            return json.loads(log['data'][0])
コード例 #2
0
    def estimate_step(self, transaction: Transaction, full_response: bool = False) -> int:
        """
        Returns an estimated step of how much step is necessary to allow the transaction to complete.

        :param transaction: a raw transaction
        :param full_response: a boolean indicating whether or not it returns refined data
        :return: an estimated step
        """
        if not isinstance(transaction, Transaction):
            raise DataTypeException("Transaction object is unrecognized.")

        params = {
            "version": convert_int_to_hex_str(transaction.version) if transaction.version else "0x3",
            "from": transaction.from_,
            "to": transaction.to,
            "timestamp": convert_int_to_hex_str(transaction.timestamp) if transaction.timestamp else get_timestamp(),
            "nid": convert_int_to_hex_str(transaction.nid) if transaction.nid else "0x1"
        }

        if transaction.value is not None:
            params["value"] = convert_int_to_hex_str(transaction.value)

        if transaction.nonce is not None:
            params["nonce"] = convert_int_to_hex_str(transaction.nonce)

        if transaction.data_type is not None:
            params["dataType"] = transaction.data_type

        if transaction.data_type in ('deploy', 'call'):
            params["data"] = generate_data_value(transaction)
        elif transaction.data_type == 'message':
            params["data"] = transaction.data

        result = self.__provider.make_request('debug_estimateStep', params, full_response)
        return result if full_response else int(result, 16)
コード例 #3
0
 def test_convert_zero_value_to_hex_str(self):
     """
     Given: Input data is zero.
     When : Converts zero value into hex string.
     Then : Gets return value correctly.
     """
     zero_value = 0
     self.assertEqual(convert_int_to_hex_str(zero_value), '0x0')
コード例 #4
0
 def test_convert_positive_value_to_hex_str(self):
     """
     Given: Input data is positive.
     When : Converts positive value into hex string.
     Then : Gets return value correctly.
     """
     positive_value = 1
     self.assertEqual(convert_int_to_hex_str(positive_value), '0x1')
コード例 #5
0
 def test_convert_negative_value_to_hex_str(self):
     """
     Given: Input data is negative.
     When : Converts negative value into hex string.
     Then : Gets return value correctly.
     """
     negative_value = -1
     self.assertEqual(convert_int_to_hex_str(negative_value), '-0x1')
コード例 #6
0
def _set_governance_variables(args) -> str:
    params = {'irep': convert_int_to_hex_str(args.irep)}

    writer = create_writer_by_args(args)
    response = writer.set_governance_variables(params)

    if response:
        return f'txHash : {response}'
コード例 #7
0
ファイル: signed_transaction.py プロジェクト: icona2/crawling
    def convert_tx_to_jsonrpc_request(transaction, wallet: Wallet = None):
        """Converts an instance of the transaction into JSON RPC request in dict"""
        dict_tx = {
            "version":
            convert_int_to_hex_str(transaction.version)
            if transaction.version else "0x3",
            "from":
            transaction.from_ if transaction.from_ else wallet.get_address(),
            "to":
            transaction.to,
            "stepLimit":
            convert_int_to_hex_str(transaction.step_limit),
            "timestamp":
            convert_int_to_hex_str(transaction.timestamp)
            if transaction.timestamp else get_timestamp(),
            "nid":
            convert_int_to_hex_str(transaction.nid)
            if transaction.nid else "0x1"
        }

        if transaction.value is not None:
            dict_tx["value"] = convert_int_to_hex_str(transaction.value)

        if transaction.nonce is not None:
            dict_tx["nonce"] = convert_int_to_hex_str(transaction.nonce)

        if transaction.data_type is not None:
            dict_tx["dataType"] = transaction.data_type

        if transaction.data_type in ('deploy', 'call'):
            dict_tx["data"] = generate_data_value(transaction)
        elif transaction.data_type == 'message':
            dict_tx["data"] = transaction.data

        return dict_tx
コード例 #8
0
    def to_dict(transaction, wallet: Wallet = None):
        """Converts an instance of the transaction into a dictionary"""
        dict_tx = {
            "version":
            convert_int_to_hex_str(transaction.version)
            if transaction.version else "0x3",
            "from":
            transaction.from_ if transaction.from_ else wallet.get_address(),
            "stepLimit":
            convert_int_to_hex_str(transaction.step_limit),
            "timestamp":
            convert_int_to_hex_str(transaction.timestamp)
            if transaction.timestamp else get_timestamp(),
            # Network ID ("0x1" for Main net, "0x2" for Test net, etc)
            "nid":
            convert_int_to_hex_str(transaction.nid)
            if transaction.nid else "0x1"
        }

        if transaction.to is not None:
            dict_tx["to"] = transaction.to

        # value can be 0
        if transaction.value is not None:
            dict_tx["value"] = convert_int_to_hex_str(transaction.value)

        if transaction.nonce is not None:
            dict_tx["nonce"] = convert_int_to_hex_str(transaction.nonce)

        if transaction.data_type is not None:
            dict_tx["dataType"] = transaction.data_type

        if transaction.data_type in ('deploy', 'call', 'message'):
            dict_tx["data"] = generate_data_value(transaction)
        return dict_tx
コード例 #9
0
def _register_proposal(args) -> dict:

    params = {
        "title": args.title,
        "description": args.desc,
        "type": convert_int_to_hex_str(int(args.type)),
        "value": None
    }

    value = _get_value_by_type(args)
    params['value'] = _convert_value_to_hex_str(value)

    writer = create_writer_by_args(args)
    if not args.yes or args.verbose:
        print_proposal_value(value)
    response = writer.register_proposal(params)

    return response