Exemple #1
0
    def setUp(self):
        self.algo = Ed25519
        self.actions = []
        self.actions.append(
            Action('contract1', 'actionname1',
                   '{\"num\": 1, \"message\": \"contract1\"}'))
        self.actions.append(Action('contract2', 'actionname2', '1'))

        self.a1 = KeyPair(self.algo)
        self.a2 = KeyPair(self.algo)
        self.a3 = KeyPair(self.algo)
Exemple #2
0
    def add_signature(self, kp: KeyPair) -> Transaction:
        """Signs the base hash of the `Transaction` and adds the `Signature` to the list of `signatures`.

        Args:
            kp: The `KeyPair` used to sign the base hash of this `Transaction`.

        Returns:
            Itself.
        """
        signature = kp.sign(self._base_hash())
        self.signatures.append(signature)
        return self
Exemple #3
0
    def test_encode_decode(self):
        info = sha3(b'hello').digest()
        seckey = sha3(b'seckey').digest()
        kp = KeyPair(Secp256k1, seckey)
        sig = Signature(info, kp)
        self.assertEqual(sig.pubkey, kp.pubkey)
        self.assertTrue(sig.verify(info))

        bsig = sig.encode()
        sig2 = Signature()
        sig2.decode(bsig)
        self.assertEqual(sig2.pubkey, sig.pubkey)
        self.assertEqual(sig2.sig, sig.sig)
        self.assertEqual(sig.algo_cls, sig2.algo_cls)
Exemple #4
0
    def add_publisher_signature(self, name: str, kp: KeyPair) -> Transaction:
        """Signs the publish hash of the `Transaction` and adds the `Signature` to the list of `publisher_signatures`.
        The publish hash includes the list of `signers` and their `signatures`.

        Args:
            name: The name of the publisher, will set the `publisher` field with its value.
            kp: The `KeyPair` used to sign the publish hash of this `Transaction`.

        Returns:
            Itself.
        """
        signature = kp.sign(self._publish_hash())
        self.publisher_signatures.append(signature)
        self.publisher = name
        self.hash = None
        return self
Exemple #5
0
    def new_account(self,
                    new_name: str,
                    creator_name: str,
                    initial_ram: int = 0,
                    initial_gas_pledge: float = 11.0,
                    initial_coins: float = 0.0,
                    algo_cls: Type[Algorithm] = Ed25519) -> Account:
        """Helper function that combines `KeyPair` and `Account` creation then calls to `create_new_account_tx` and `send_and_wait_tx`.

        Creates an `Account` with new ``owner`` and ``active`` `KeyPair`, then
            creates a `Transaction` that contains a list of `Actions` to create an account,
            pledge tokens, buy RAM and transfer coins to the new account, and finally sends it.

        Args:
            new_name: The name of the account to create.
            creator_name: The name of the account that will pledge tokens to the new account.
            initial_ram: The amount of RAM to buy for the new account.
            initial_gas_pledge: The amount of tokens to pledge for the new account.
            initial_coins: The amount of coins to transfer to the new account.
            algo_cls: The class type of the `Algorithm` to use to generate the `KeyPair`.

        Returns:
            A `Account` object.

        Raises:
            TransactionError: If Transaction.Status is unknown or if TxReceipt.StatusCode is not SUCCESS.
            TimeoutError: If TxReceipt.StatusCode is TIMEOUT
                or no transaction can be found after `wait_time` x `wait_max_retry` have passed.
        """
        account = Account(new_name)
        kp = KeyPair(algo_cls)
        account.add_key_pair(kp, 'owner')
        account.add_key_pair(kp, 'active')

        tx = self.create_new_account_tx(
            new_name, creator_name,
            b58encode(account.get_key_pair('owner').pubkey),
            b58encode(account.get_key_pair('active').pubkey), initial_ram,
            initial_gas_pledge, initial_coins)
        self.send_and_wait_tx(tx)
        return account
Exemple #6
0
import time
from pyost.iost import IOST
from pyost.account import Account
from pyost.algorithm import Ed25519
from pyost.signature import KeyPair
from base58 import b58decode

if __name__ == '__main__':
    iost = IOST('localhost:30002')

    admin_seckey = b58decode(
        b'1rANSfcRzr4HkhbUFZ7L1Zp69JZZHiDDq5v7dNSbbEqeU4jxy3fszV4HGiaLQEyqVpS1dKT9g7zCVRxBVzuiUzB'
    )
    admin_kp = KeyPair(Ed25519, admin_seckey)
    admin = Account('producer00001')
    admin.add_key_pair(admin_kp, 'active')
    admin.add_key_pair(admin_kp, 'owner')

    account_seckey = b58decode(
        b'4vZ8qw2MaGLVXsbW7TcyTDcEqrefAS34vuM1eJf7YrBL9Fpnq3LgRyDjnUfv7kjvPfsA5tQGnou3Bv2bYNXyorK1'
    )
    account_kp = KeyPair(Ed25519, account_seckey)
    account = Account('testacc1')
    account.add_key_pair(account_kp, 'active')
    account.add_key_pair(account_kp, 'owner')

    # Create token
    token_sym = 't' + str(int(time.time() * 1000000))[-4:]
    tx = iost.create_call_tx('token.iost', 'create', token_sym, admin.name,
                             21000000, {
                                 "fullName": "bit coin",
Exemple #7
0
from pyost.signature import KeyPair
from pyost.transaction import TransactionError
from base58 import b58decode


def print_balance(account_name: str):
    account = iost.get_account_info(account_name)
    print(
        f'{account.name}: balance={account.balance} gas={account.gas_info.current_total} ram={account.ram_info.available}')


if __name__ == '__main__':
    iost = IOST('localhost:30002')

    admin_seckey = b58decode(b'1rANSfcRzr4HkhbUFZ7L1Zp69JZZHiDDq5v7dNSbbEqeU4jxy3fszV4HGiaLQEyqVpS1dKT9g7zCVRxBVzuiUzB')
    admin_kp = KeyPair(Ed25519, admin_seckey)
    admin = Account('admin')
    admin.add_key_pair(admin_kp, 'active')
    admin.add_key_pair(admin_kp, 'owner')
    acc1 = admin
    print_balance(acc1.name)

    acc2_seckey = b58decode(b'4vZ8qw2MaGLVXsbW7TcyTDcEqrefAS34vuM1eJf7YrBL9Fpnq3LgRyDjnUfv7kjvPfsA5tQGnou3Bv2bYNXyorK1')
    acc2_kp = KeyPair(Ed25519, acc2_seckey)
    acc2 = Account('producer01')
    acc2.add_key_pair(acc2_kp, 'active')
    acc2.add_key_pair(acc2_kp, 'owner')
    print_balance(acc2.name)

    tx = iost.create_transfer_tx('iost', acc1.name, acc2.name, 10000)
Exemple #8
0
from base58 import b58decode
from pyost.iost import IOST
from pyost.account import Account
from pyost.algorithm import Secp256k1, Ed25519
from pyost.signature import KeyPair
from pyost.transaction import TransactionError

if __name__ == '__main__':
    iost = IOST('localhost:30002')

    acc_seckey = b58decode(
        b'1rANSfcRzr4HkhbUFZ7L1Zp69JZZHiDDq5v7dNSbbEqeU4jxy3fszV4HGiaLQEyqVpS1dKT9g7zCVRxBVzuiUzB'
    )
    acc_kp = KeyPair(Ed25519, acc_seckey)
    acc = Account('admin')
    acc.add_key_pair(acc_kp, 'active')
    acc.add_key_pair(acc_kp, 'owner')

    print('Account Info:')
    print(iost.get_account_info(acc.name))

    print('\nToken Balance:')
    print(iost.get_token_balance(acc.name))

    print('\nToken 721 Balance:')
    print(iost.get_token721_balance(acc.name, 'iost'))

    tx = iost.create_call_tx('token.iost', 'supply', 'iost')
    acc.sign_publish(tx)
    try:
        receipt = iost.send_and_wait_tx(tx)
Exemple #9
0
from hashlib import sha3_256 as sha3
from base64 import b64encode

from pyost.algorithm import Ed25519, Secp256k1
from pyost.signature import KeyPair

if __name__ == '__main__':
    text = b'hello'
    info = sha3(text).digest()
    print(info.hex())

    for algo in [Ed25519, Secp256k1]:
        kp = KeyPair(algo)
        print(kp.algo_cls.__int__())
        print(kp.seckey.hex())
        print(kp.pubkey.hex())

        sig = kp.sign(info)
        print(sig.pubkey.hex())
        print(sig.sig.hex())
        print(b64encode(sig.pubkey))
        print(b64encode(sig.sig))
Exemple #10
0
from base58 import b58decode
from pyost.iost import IOST
from pyost.account import Account
from pyost.algorithm import Ed25519
from pyost.signature import KeyPair

if __name__ == '__main__':
    iost = IOST('localhost:30002')

    account_seckey = b58decode(
        b'4vZ8qw2MaGLVXsbW7TcyTDcEqrefAS34vuM1eJf7YrBL9Fpnq3LgRyDjnUfv7kjvPfsA5tQGnou3Bv2bYNXyorK1')
    account_kp = KeyPair(Ed25519, account_seckey)
    account = Account('testacc1')
    account.add_key_pair(account_kp, 'active')
    account.add_key_pair(account_kp, 'owner')

    print(f'Account RAM: {iost.get_account_info(account.name).ram_info.available}')

    print(f'RAM price: {iost.get_ram_info().buy_price}')
    tx = iost.create_call_tx('ram.iost', 'buy', account.name, account.name, 50000)
    tx.gas_limit = 1000000
    account.sign_publish(tx)

    print('Waiting for transaction to be processed...')
    try:
        receipt = iost.send_and_wait_tx(tx)
        print(receipt)
    except TimeoutError as e:
        print(f'ERROR: {e}')
    except RuntimeError as e:
        print(f'ERROR: {e}')