Ejemplo n.º 1
0
def cloneaccount(ctx, account_name, account):
    """ Clone an account

        This copies the owner and active permissions as well as the
        options (e.g. votes, memo key)
    """
    from bitsharesbase import transactions, operations
    account = Account(account)
    op = {
        "fee": {
            "amount": 0,
            "asset_id": "1.3.0"
        },
        "registrar": account["id"],
        "referrer": account["id"],
        "referrer_percent": 100,
        "name": account_name,
        'owner': account["owner"],
        'active': account["active"],
        "options": account["options"],
        "extensions": {},
        "prefix": ctx.bitshares.rpc.chain_params["prefix"]
    }
    op = operations.Account_create(**op)
    pprint(ctx.bitshares.finalizeOp(op, account, "active"))
Ejemplo n.º 2
0
def create_account(inst, name, 
                    owner='CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K',
                    active='CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K'):
    '''
    create account using below keys:
    name - name
    owner - CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K
    active - CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K
    pri - 5HsGZoidEURBx8gYzwZMeM2eF8P3F9KC3nVAib2mdGSdj6FqS7h
    '''
    if inst.wallet.locked():
        inst.wallet.unlock(CFG['wallet']['test_wallet_pwd'])
    try:
        ## private key of nathan, which is the referrer
        inst.wallet.addPrivateKey(inst.const['master_privkey'])
    except Exception as e:
        pass
    
    toRegister = {
        'name': name,
        'owner': owner,
        'active': active
    }
    account = cybex.Account('nathan')
    owner_key_authority = [[toRegister["owner"], 1]]
    active_key_authority = [[toRegister["active"], 1]]
    owner_accounts_authority = []
    active_accounts_authority = []    
    kwargs = {
        'fee':{"amount": 100, "asset_id": "1.3.0"},
        'registrar':account["id"],
        'referrer':account["id"],
        'referrer_percent':1,
        'name':toRegister["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": toRegister["active"],
                    "voting_account": account["id"],
                    "num_witness": 0,
                    "num_committee": 0,
                    "votes": [],
                    "extensions": []
                    },
        "extensions": {},
        "prefix": "CYB"
    }
    op = operations.Account_create(**kwargs)
    ops=[]
    ops.append(op)
    inst.finalizeOp(ops, account, "active")
    return True
Ejemplo n.º 3
0
def create_buyback_account(name, asset, buyback_markets):
    """
    Only asset issuer can create a buyback account on that asset
    name: like 'abc-def'
    asset: like '1.3.2'
    buyback_markets: like ['1.3.3', '1.3.4']
    """
    if inst.wallet.locked():
        inst.wallet.unlock(TEST_WALLET_PWD)
    try:
        ## private key of nathan, which is the referrer
        inst.wallet.addPrivateKey(private)
    except Exception as e:
        pass
    
    account = cybex.Account('nathan')

    kwargs = {
        'fee':{"amount": 100, "asset_id": "1.3.0"},
        'registrar':account["id"],
        'referrer':account["id"],
        'referrer_percent':1,
        'name':name,
        'owner': {'account_auths': [['1.2.3', 1]],
                    'key_auths': [],
                    "address_auths": [],
                    'weight_threshold': 1},
        'active': {'account_auths': [['1.2.3', 1]],
                    'key_auths': [],
                    "address_auths": [],
                    'weight_threshold': 1},
        "options": {"memo_key": 'CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K',
                    "voting_account": account["id"],
                    "num_witness": 0,
                    "num_committee": 0,
                    "votes": [],
                    "extensions": []
                    },
        "extensions": {'buyback_options': {'asset_to_buy': asset_id, 'asset_to_buy_issuer': account['id'], 'markets': buyback_markets}},
        "prefix": "CYB"
    }

    op = operations.Account_create(**kwargs)
    ops=[]
    ops.append(op)
    inst.finalizeOp(ops, account, "active")
    return True
Ejemplo n.º 4
0
    def compareNewWire(self):
        #    def test_online(self):
        #        self.maxDiff = None

        from grapheneapi.grapheneapi import GrapheneAPI
        rpc = GrapheneAPI("localhost", 8092)
        tx = rpc.create_account("xeroc", "fsafaasf", "", False)
        pprint(tx)
        compare = rpc.serialize_transaction(tx)
        ref_block_num = tx["ref_block_num"]
        ref_block_prefix = tx["ref_block_prefix"]
        expiration = tx["expiration"]

        ops = [Operation(operations.Account_create(**tx["operations"][0][1]))]
        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], "BTS")
        txWire = hexlify(bytes(tx)).decode("ascii")
        print("\n")
        print(txWire[:-130])
        print(compare[:-130])
Ejemplo n.º 5
0
 def test_create_account(self):
     self.maxDiff = None
     self.op = operations.Account_create(
         **{
             "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.cm = ("f68585abf4dce7c804570105f26416000000000000211b03000b666f"
                "6f6261722d6631323401000000000202fe8cc11cc8251de6977636b5"
                "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91"
                "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01"
                "000001000000000303b453f46013fdbccb90b09ba169c388c34d8445"
                "4a3b9fbec68d5a7819a734fca0010002fe8cc11cc8251de6977636b5"
                "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91"
                "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01"
                "0000024ab336b4b14ba6d881675d1c782912783c43dbbe31693aa710"
                "ac1896bd7c3d61050000000000000000011f024373610743cab92abc"
                "197cc69aa04c45e20a8c1c495629ca5765d8e458a18f0920bfaf9d0a"
                "909c01819cf887a66d06903af71fb07f0aac34600c733590984e")
     self.doit(1)
 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':
             [['BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1],
              ['BTS6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp', 1]],
             "address_auths": []
         },
         "active": {
             "weight_threshold":
             1,
             "account_auths": [],
             'key_auths':
             [['BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1],
              ['BTS6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp', 1],
              ['BTS8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7', 1]],
             "address_auths": []
         },
         "options": {
             "memo_key":
             "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE",
             "voting_account": "1.2.5",
             "num_witness": 0,
             "num_committee": 0,
             "votes": [],
             "extensions": []
         },
         "extensions": {}
     }
     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], "BTS")
     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])
Ejemplo n.º 7
0
 def test_create_account(self):
     self.op = operations.Account_create(**{
         "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': [['BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x',
                                 1], [
                                 'BTS6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp',
                                 1]],
                   "address_auths": []
                   },
         "active": {"weight_threshold": 1,
                    "account_auths": [],
                    'key_auths': [['BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x',
                                   1], [
                                  'BTS6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp',
                                  1], [
                                  'BTS8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7',
                                  1
                                  ]],
                    "address_auths": []
                    },
         "options": {"memo_key": "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE",
                     "voting_account": "1.2.5",
                     "num_witness": 0,
                     "num_committee": 0,
                     "votes": [],
                     "extensions": []
                     },
         "extensions": {
             "buyback_options": {
                 "asset_to_buy": "1.3.127",
                 "asset_to_buy_issuer": "1.2.31",
                 "markets": ["1.3.20"]},
             "null_ext": {},
             "owner_special_authority":
                 [1, {"asset": "1.3.127",
                      "num_top_holders": 10}]
         },
         "prefix": "BTS"
     })
     self.cm = ("f68585abf4dce7c804570105f26416000000000000211b03000b666f"
                "6f6261722d6631323401000000000202fe8cc11cc8251de6977636b5"
                "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91"
                "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01"
                "000001000000000303b453f46013fdbccb90b09ba169c388c34d8445"
                "4a3b9fbec68d5a7819a734fca0010002fe8cc11cc8251de6977636b5"
                "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91"
                "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01"
                "0000024ab336b4b14ba6d881675d1c782912783c43dbbe31693aa710"
                "ac1896bd7c3d6105000000000000030001017f0a037f1f0114000120"
                "508168b9615d48bd11846b3b9bcf000d1424a7915fb1cfa7f61150b5"
                "435c060b3147c056a1f889633c43d1b88cb463e8083fa2b62a585af9"
                "e1b7a7c23d83ae78")
     self.doit()
Ejemplo n.º 8
0
    def create_account(
        self,
        account_name,
        registrar=None,
        referrer="1.2.35641",
        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 BitShares

            The brainkey/password can be used to recover all generated keys (see
            `bitsharesbase.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 uptick")
        if password and (owner_key or active_key or memo_key):
            raise ValueError("You cannot use 'password' AND provide keys!")

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

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

        " Generate new keys from password"
        from bitsharesbase.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, bitshares_instance=self)
            owner_accounts_authority.append([addaccount["id"], 1])
        for k in additional_active_accounts:
            addaccount = Account(k, bitshares_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")