コード例 #1
0
 def test_create_account(self):
     s = {
         "fee": {"amount": 1467634, "asset_id": "1.3.0"},
         "registrar": "1.2.33",
         "referrer": "1.2.27",
         "referrer_percent": 3,
         "name": "foobar-f124",
         "owner": {
             "weight_threshold": 1,
             "account_auths": [],
             "key_auths": [
                 [prefix + "6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x", 1],
                 [prefix + "6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp", 1],
             ],
             "address_auths": [],
         },
         "active": {
             "weight_threshold": 1,
             "account_auths": [],
             "key_auths": [
                 [prefix + "6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x", 1],
                 [prefix + "6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp", 1],
                 [prefix + "8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7", 1],
             ],
             "address_auths": [],
         },
         "options": {
             "memo_key": prefix
             + "5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE",
             "voting_account": "1.2.5",
             "num_witness": 0,
             "num_committee": 0,
             "votes": [],
             "extensions": [],
         },
         "extensions": {},
         "prefix": prefix,
     }
     self.op = operations.Account_create(**s)
     self.cm = (
         "f68585abf4dce7c804570105f26416000000000000211b03000b666f"
         "6f6261722d6631323401000000000202fe8cc11cc8251de6977636b5"
         "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91"
         "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01"
         "000001000000000303b453f46013fdbccb90b09ba169c388c34d8445"
         "4a3b9fbec68d5a7819a734fca0010002fe8cc11cc8251de6977636b5"
         "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91"
         "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01"
         "0000024ab336b4b14ba6d881675d1c782912783c43dbbe31693aa710"
         "ac1896bd7c3d61050000000000000000011f61ad276120bc3f189296"
         "2bfff7db5e8ce04d5adec9309c80529e3a978a4fa1073225a6d56929"
         "e34c9d2a563e67a8f4a227e4fadb4a3bb6ec91bfdf4e57b80efd"
     )
     self.doit()
コード例 #2
0
    def create_account(
        self,
        account_name,
        registrar=None,
        referrer="1.2.0",
        referrer_percent=50,
        owner_key=None,
        active_key=None,
        memo_key=None,
        password=None,
        additional_owner_keys=[],
        additional_active_keys=[],
        additional_owner_accounts=[],
        additional_active_accounts=[],
        proxy_account="proxy-to-self",
        storekeys=True,
    ):
        """ Create new account on PeerPlays

            The brainkey/password can be used to recover all generated keys (see
            `peerplaysbase.account` for more details.

            By default, this call will use ``default_account`` to
            register a new name ``account_name`` with all keys being
            derived from a new brain key that will be returned. The
            corresponding keys will automatically be installed in the
            wallet.

            .. warning:: Don't call this method unless you know what
                          you are doing! Be sure to understand what this
                          method does and where to find the private keys
                          for your account.

            .. note:: Please note that this imports private keys
                      (if password is present) into the wallet by
                      default. However, it **does not import the owner
                      key** for security reasons. Do NOT expect to be
                      able to recover it from the wallet if you lose
                      your password!

            :param str account_name: (**required**) new account name
            :param str registrar: which account should pay the registration fee
                                (defaults to ``default_account``)
            :param str owner_key: Main owner key
            :param str active_key: Main active key
            :param str memo_key: Main memo_key
            :param str password: Alternatively to providing keys, one
                                 can provide a password from which the
                                 keys will be derived
            :param array additional_owner_keys:  Additional owner public keys
            :param array additional_active_keys: Additional active public keys
            :param array additional_owner_accounts: Additional owner account names
            :param array additional_active_accounts: Additional acctive account names
            :param bool storekeys: Store new keys in the wallet (default: ``True``)
            :raises AccountExistsException: if the account already exists on the blockchain

        """
        if not registrar and config["default_account"]:
            registrar = config["default_account"]
        if not registrar:
            raise ValueError(
                "Not registrar account given. Define it with " +
                "registrar=x, or set the default_account using 'peerplays'")
        if password and (owner_key or active_key or memo_key):
            raise ValueError("You cannot use 'password' AND provide keys!")

        try:
            Account(account_name, peerplays_instance=self)
            raise AccountExistsException
        except:
            pass

        referrer = Account(referrer, peerplays_instance=self)
        registrar = Account(registrar, peerplays_instance=self)

        " Generate new keys from password"
        from peerplaysbase.account import PasswordKey, PublicKey
        if password:
            active_key = PasswordKey(account_name, password, role="active")
            owner_key = PasswordKey(account_name, password, role="owner")
            memo_key = PasswordKey(account_name, password, role="memo")
            active_pubkey = active_key.get_public_key()
            owner_pubkey = owner_key.get_public_key()
            memo_pubkey = memo_key.get_public_key()
            active_privkey = active_key.get_private_key()
            # owner_privkey   = owner_key.get_private_key()
            memo_privkey = memo_key.get_private_key()
            # store private keys
            if storekeys:
                # self.wallet.addPrivateKey(owner_privkey)
                self.wallet.addPrivateKey(active_privkey)
                self.wallet.addPrivateKey(memo_privkey)
        elif (owner_key and active_key and memo_key):
            active_pubkey = PublicKey(active_key,
                                      prefix=self.rpc.chain_params["prefix"])
            owner_pubkey = PublicKey(owner_key,
                                     prefix=self.rpc.chain_params["prefix"])
            memo_pubkey = PublicKey(memo_key,
                                    prefix=self.rpc.chain_params["prefix"])
        else:
            raise ValueError(
                "Call incomplete! Provide either a password or public keys!")
        owner = format(owner_pubkey, self.rpc.chain_params["prefix"])
        active = format(active_pubkey, self.rpc.chain_params["prefix"])
        memo = format(memo_pubkey, self.rpc.chain_params["prefix"])

        owner_key_authority = [[owner, 1]]
        active_key_authority = [[active, 1]]
        owner_accounts_authority = []
        active_accounts_authority = []

        # additional authorities
        for k in additional_owner_keys:
            owner_key_authority.append([k, 1])
        for k in additional_active_keys:
            active_key_authority.append([k, 1])

        for k in additional_owner_accounts:
            addaccount = Account(k, peerplays_instance=self)
            owner_accounts_authority.append([addaccount["id"], 1])
        for k in additional_active_accounts:
            addaccount = Account(k, peerplays_instance=self)
            active_accounts_authority.append([addaccount["id"], 1])

        # voting account
        voting_account = Account(proxy_account or "proxy-to-self")

        op = {
            "fee": {
                "amount": 0,
                "asset_id": "1.3.0"
            },
            "registrar": registrar["id"],
            "referrer": referrer["id"],
            "referrer_percent": referrer_percent * 100,
            "name": account_name,
            'owner': {
                'account_auths': owner_accounts_authority,
                'key_auths': owner_key_authority,
                "address_auths": [],
                'weight_threshold': 1
            },
            'active': {
                'account_auths': active_accounts_authority,
                'key_auths': active_key_authority,
                "address_auths": [],
                'weight_threshold': 1
            },
            "options": {
                "memo_key": memo,
                "voting_account": voting_account["id"],
                "num_witness": 0,
                "num_committee": 0,
                "votes": [],
                "extensions": []
            },
            "extensions": {},
            "prefix": self.rpc.chain_params["prefix"]
        }
        op = operations.Account_create(**op)
        return self.finalizeOp(op, registrar, "active")
コード例 #3
0
 def test_create_account(self):
     s = {
         "fee": {
             "amount": 1467634,
             "asset_id": "1.3.0"
         },
         "registrar": "1.2.33",
         "referrer": "1.2.27",
         "referrer_percent": 3,
         "name": "foobar-f124",
         "owner": {
             "weight_threshold":
             1,
             "account_auths": [],
             'key_auths':
             [[
                 prefix +
                 '6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1
             ],
              [
                  prefix +
                  '6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp', 1
              ]],
             "address_auths": []
         },
         "active": {
             "weight_threshold":
             1,
             "account_auths": [],
             'key_auths':
             [[
                 prefix +
                 '6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1
             ],
              [
                  prefix +
                  '6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp', 1
              ],
              [
                  prefix +
                  '8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7', 1
              ]],
             "address_auths": []
         },
         "options": {
             "memo_key":
             prefix + '5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE',
             "voting_account": "1.2.5",
             "num_witness": 0,
             "num_committee": 0,
             "votes": [],
             "extensions": []
         },
         "extensions": {},
         "prefix": prefix
     }
     op = operations.Account_create(**s)
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], prefix)
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c804570105f26416000000000000211b03000b666f"
                "6f6261722d6631323401000000000202fe8cc11cc8251de6977636b5"
                "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91"
                "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01"
                "000001000000000303b453f46013fdbccb90b09ba169c388c34d8445"
                "4a3b9fbec68d5a7819a734fca0010002fe8cc11cc8251de6977636b5"
                "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91"
                "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01"
                "0000024ab336b4b14ba6d881675d1c782912783c43dbbe31693aa710"
                "ac1896bd7c3d61050000000000000000011f61ad276120bc3f189296"
                "2bfff7db5e8ce04d5adec9309c80529e3a978a4fa1073225a6d56929"
                "e34c9d2a563e67a8f4a227e4fadb4a3bb6ec91bfdf4e57b80efd")
     self.assertEqual(compare[:-130], txWire[:-130])