Example #1
0
    def __init__(self,
                 payer,
                 receiver,
                 stake_net_quantity,
                 stake_cpu_quantity,
                 permission=None,
                 transfer=False,
                 expiration_sec=30,
                 skip_signature=0,
                 dont_broadcast=0,
                 forceUnique=0,
                 max_cpu_usage=0,
                 max_net_usage=0,
                 ref_block=None,
                 is_verbose=1):

        self.payer = interface.account_arg(payer)
        self.receiver = interface.account_arg(receiver)
        self.stake_net_quantity = stake_net_quantity
        self.stake_cpu_quantity = stake_cpu_quantity

        args = [
            self.payer, self.receiver,
            "{} EOS".format(self.stake_net_quantity),
            "{} EOS".format(self.stake_cpu_quantity), "--expiration",
            str(expiration_sec), "--json"
        ]

        if not permission is None:
            p = interface.permission_arg(permission)
            for perm in p:
                args.extend(["--permission", perm])
        if transfer:
            args.append("--transfer")
        if skip_signature:
            args.append("--skip-sign")
        if dont_broadcast:
            args.append("--dont-broadcast")
        if forceUnique:
            args.append("--force-unique")
        if max_cpu_usage:
            args.extend(["--max-cpu-usage-ms", str(max_cpu_usage)])
        if max_net_usage:
            args.extend(["--max-net-usage", str(max_net_usage)])
        if not ref_block is None:
            args.extend(["--ref-block", ref_block])

        cleos._Cleos.__init__(self, args, "system", "delegatebw", is_verbose)

        self.ERROR()
Example #2
0
    def __init__(self,
                 account,
                 contract_dir,
                 wasm_file=None,
                 abi_file=None,
                 permission=None,
                 expiration_sec=30,
                 skip_signature=0,
                 dont_broadcast=0,
                 forceUnique=0,
                 max_cpu_usage=0,
                 max_net_usage=0,
                 ref_block=None,
                 is_verbose=True,
                 json=False):

        files = contract_is_built(contract_dir, wasm_file, abi_file)
        if not files:
            raise errors.Error("""
            Cannot determine the contract directory. The clue is 
            {}.
            """.format(contract_dir))
            return

        self.contract_path_absolute = files[0]
        wasm_file = files[1]
        abi_file = files[2]

        self.account_name = interface.account_arg(account)

        args = [self.account_name, self.contract_path_absolute]

        if json:
            args.append("--json")
        if not permission is None:
            p = interface.permission_arg(permission)
            for perm in p:
                args.extend(["--permission", perm])

        args.extend(["--expiration", str(expiration_sec)])
        if skip_signature:
            args.append("--skip-sign")
        if dont_broadcast:
            args.append("--dont-broadcast")
        if forceUnique:
            args.append("--force-unique")
        if max_cpu_usage:
            args.extend(["--max-cpu-usage-ms", str(max_cpu_usage)])
        if max_net_usage:
            args.extend(["--max-net-usage", str(max_net_usage)])
        if not ref_block is None:
            args.extend(["--ref-block", ref_block])
        if wasm_file:
            args.append(wasm_file)
        if abi_file:
            args.append(abi_file)

        _Cleos.__init__(self, args, "set", "contract", is_verbose)

        self.printself()
Example #3
0
 def __init__(self, account):
     self.account = account
     Error.__init__(
         self, 
         "Account ``{}`` does not exist in the blockchain."
         .format(interface.account_arg(account)), 
         True)
Example #4
0
    def __init__(self,
                 account,
                 action,
                 data,
                 permission=None,
                 expiration_sec=30,
                 skip_signature=0,
                 dont_broadcast=0,
                 forceUnique=0,
                 max_cpu_usage=0,
                 max_net_usage=0,
                 ref_block=None,
                 is_verbose=True,
                 json=False):
        self.account_name = interface.account_arg(account)

        args = [self.account_name, action, data]
        if json:
            args.append("--json")
        if not permission is None:
            p = interface.permission_arg(permission)
            for perm in p:
                args.extend(["--permission", perm])

        args.extend(["--expiration", str(expiration_sec)])
        if skip_signature:
            args.append("--skip-sign")
        if dont_broadcast:
            args.append("--dont-broadcast")
        if forceUnique:
            args.append("--force-unique")
        if max_cpu_usage:
            args.extend(["--max-cpu-usage-ms", str(max_cpu_usage)])
        if max_net_usage:
            args.extend(["--max-net-usage", str(max_net_usage)])
        if not ref_block is None:
            args.extend(["--ref-block", ref_block])

        self.console = None
        self.data = None
        _Cleos.__init__(self, args, "push", "action", is_verbose)

        if not dont_broadcast:
            self.console = self.json["processed"]["action_traces"][0][
                "console"]
            self.data = self.json["processed"]["action_traces"][0]["act"][
                "data"]

        self.printself()
Example #5
0
    def __init__(self,
                 payer,
                 receiver,
                 amount,
                 buy_ram_kbytes=0,
                 expiration_sec=30,
                 skip_signature=0,
                 dont_broadcast=0,
                 forceUnique=0,
                 max_cpu_usage=0,
                 max_net_usage=0,
                 ref_block=None,
                 is_verbose=1):

        self.payer = interface.account_arg(payer)
        self.receiver = interface.account_arg(receiver)
        self.amount = str(amount)

        args = [self.payer, self.receiver, self.amount]

        if buy_ram_kbytes:
            args.extend(["--kbytes"])
        if skip_signature:
            args.append("--skip-sign")
        if dont_broadcast:
            args.append("--dont-broadcast")
        if forceUnique:
            args.append("--force-unique")
        if max_cpu_usage:
            args.extend(["--max-cpu-usage-ms", str(max_cpu_usage)])
        if max_net_usage:
            args.extend(["--max-net-usage", str(max_net_usage)])
        if not ref_block is None:
            args.extend(["--ref-block", ref_block])

        cleos._Cleos.__init__(self, args, "system", "buyram", is_verbose)
Example #6
0
    def __init__(self, account, code="", abi="", wasm=False, is_verbose=True):

        account_name = interface.account_arg(account)

        args = [account_name]
        if code:
            args.extend(["--code", code])
        if abi:
            args.extend(["--abi", abi])
        if wasm:
            args.extend(["--wasm"])

        _Cleos.__init__(self, args, "get", "code", is_verbose)

        msg = str(self.out_msg)
        self.json["code_hash"] = msg[msg.find(":") + 2:len(msg) - 1]
        self.code_hash = self.json["code_hash"]
        self.printself()
Example #7
0
    def __init__(self,
                 account,
                 table,
                 scope,
                 binary=False,
                 limit=10,
                 key="",
                 lower="",
                 upper="",
                 is_verbose=True):
        args = [interface.account_arg(account)]

        if not scope:
            scope = self.name
        else:
            try:
                scope_name = scope.name
            except:
                scope_name = scope

        args.append(scope_name)
        args.append(table)

        if binary:
            args.append("--binary")
        if limit:
            args.extend(["--limit", str(limit)])
        if key:
            args.extend([
                "--key",
                interface.key_arg(key,
                                  is_owner_key=False,
                                  is_private_key=False)
            ])
        if lower:
            args.extend(["--lower", lower])
        if upper:
            args.extend(["--upper", upper])

        _Cleos.__init__(self, args, "get", "table", is_verbose)

        self.printself()
Example #8
0
    def __init__(self, account, is_info=True, is_verbose=True):
        interface.Account.__init__(self, interface.account_arg(account))
        _Cleos.__init__(self,
                        [self.name] if is_info else [self.name, "--json"],
                        "get", "account", is_verbose)

        self.owner_key = None
        self.active_key = None
        if not is_info:
            if self.json["permissions"][1]["required_auth"]["keys"]:
                self.owner_key = self.json["permissions"][1] \
                    ["required_auth"]["keys"][0]["key"]
                self.active_key = self.json["permissions"][0] \
                    ["required_auth"]["keys"][0]["key"]
        else:
            owner = re.search('owner\s+1\:\s+1\s(.*)\n', self.out_msg)
            active = re.search('active\s+1\:\s+1\s(.*)\n', self.out_msg)
            if owner and active:
                self.owner_key = owner.group(1)
                self.active_key = active.group(1)

        self.printself()
Example #9
0
    def __init__(self,
                 creator,
                 name,
                 owner_key,
                 active_key,
                 stake_net,
                 stake_cpu,
                 permission=None,
                 buy_ram_kbytes=0,
                 buy_ram="",
                 transfer=False,
                 expiration_sec=30,
                 skip_signature=0,
                 dont_broadcast=0,
                 forceUnique=0,
                 max_cpu_usage=0,
                 max_net_usage=0,
                 ref_block=None,
                 is_verbose=1):

        stake_net = "{} EOS".format(stake_net)
        stake_cpu = "{} EOS".format(stake_cpu)

        if name is None:
            name = account_name()
        interface.Account.__init__(self, name)

        self.owner_key = None  # private keys
        self.active_key = None

        if active_key is None:
            active_key = owner_key

        args = [
            interface.account_arg(creator), self.name,
            interface.key_arg(owner_key,
                              is_owner_key=True,
                              is_private_key=False),
            interface.key_arg(active_key,
                              is_owner_key=False,
                              is_private_key=False)
        ]

        args.append("--json")
        args.extend(["--stake-net", stake_net, "--stake-cpu", stake_cpu])
        if buy_ram_kbytes:
            args.extend(["--buy-ram-kbytes", str(buy_ram_kbytes)])
        if buy_ram:
            args.extend(["--buy-ram", str(buy_ram)])
        if transfer:
            args.extend(["--transfer"])
        if not permission is None:
            p = interface.permission_arg(permission)
            for perm in p:
                args.extend(["--permission", perm])
        if skip_signature:
            args.append("--skip-sign")
        if dont_broadcast:
            args.append("--dont-broadcast")
        if forceUnique:
            args.append("--force-unique")
        if max_cpu_usage:
            args.extend(["--max-cpu-usage-ms", str(max_cpu_usage)])
        if max_net_usage:
            args.extend(["--max-net-usage", str(max_net_usage)])
        if not ref_block is None:
            args.extend(["--ref-block", ref_block])

        cleos._Cleos.__init__(self, args, "system", "newaccount", is_verbose)

        self.json = cleos.GetAccount(self.name, is_verbose=0,
                                     is_info=False).json

        if self.is_verbose:
            print(self.__str__())
Example #10
0
    def __init__(self,
                 creator,
                 name,
                 owner_key,
                 active_key=None,
                 permission=None,
                 expiration_sec=30,
                 skip_signature=0,
                 dont_broadcast=0,
                 forceUnique=0,
                 max_cpu_usage=0,
                 max_net_usage=0,
                 ref_block=None,
                 is_verbose=True):

        if name is None:
            name = account_name()
        interface.Account.__init__(self, name)

        self.owner_key = None  # private keys
        self.active_key = None

        if active_key is None:
            active_key = owner_key

        owner_key_public = interface.key_arg(owner_key,
                                             is_owner_key=True,
                                             is_private_key=False)
        active_key_public = interface.key_arg(active_key,
                                              is_owner_key=False,
                                              is_private_key=False)

        args = [
            interface.account_arg(creator), self.name, owner_key_public,
            active_key_public
        ]

        args.append("--json")
        if not permission is None:
            p = interface.permission_arg(permission)
            for perm in p:
                args.extend(["--permission", perm])

        args.extend(["--expiration", str(expiration_sec)])
        if skip_signature:
            args.append("--skip-sign")
        if dont_broadcast:
            args.append("--dont-broadcast")
        if forceUnique:
            args.append("--force-unique")
        if max_cpu_usage:
            args.extend(["--max-cpu-usage-ms", str(max_cpu_usage)])
        if max_net_usage:
            args.extend(["--max-net-usage", str(max_net_usage)])
        if not ref_block is None:
            args.extend(["--ref-block", ref_block])

        _Cleos.__init__(self, args, "create", "account", is_verbose)

        self.json = GetAccount(self.name, is_verbose=False, is_info=False).json
        self.printself()