def setup_class(cls):
        eosapi.set_node('http://127.0.0.1:9000')
        eosapi_async = ChainApiAsync('http://127.0.0.1:9000')

        cls.testnet = Testnet(single_node=True, show_log=False)
        cls.testnet.run()
        cls.info = eosapi.get_info()
        # logger.info(cls.info)
        cls.chain_id = cls.info['chain_id']
 def test_push_tx(self):
     tx = self.gen_tx()
     public_keys = ['EOS7sPDxfw5yx5SZgQcVb57zS1XeSWLNpQKhaGjjy2qe61BrAQ49o',]
     info = eosapi.get_info()
     # account_info = eosapi.get_account('helloworld11')
     # logger.info(account_info)
     signed_tx = wallet.sign_transaction(tx, public_keys, info['chain_id'])
     logger.info(signed_tx)
     r = eosapi.push_transaction(signed_tx)
     logger.info('+++++++++elapsed:%s', r['processed']['elapsed'])
 def gen_tx(self):
     args = {
         'from': 'helloworld11',
         'to': 'eosio',
         'quantity': '0.0100 EOS',
         'memo': 'hello'
     }
     action = ['eosio.token', 'transfer', args, {'helloworld11': 'active'}]
     chain_info = eosapi.get_info()
     chain_id = chain_info['chain_id']
     reference_block_id = chain_info['head_block_id']
     tx = eosapi.generate_transaction([action], 60, reference_block_id, chain_id)
     return tx
    def test_get_required_keys(self):
        args = {
            'from': 'helloworld11',
            'to': 'helloworld12',
            'quantity': '0.0100 EOS',
            'memo': 'hello'
        }
        act = ['eosio.token', 'transfer', args, {'helloworld11': 'active'}]
        chain_info = eosapi.get_info()
        reference_block_id = chain_info['head_block_id']
        trx = eosapi.generate_transaction([act], 60, reference_block_id)
        keys = eosapi.get_required_keys(trx, wallet.get_public_keys())
        assert keys

        chain_id = chain_info['chain_id']
        trx = wallet.sign_transaction(trx, keys, chain_id, json=True)
        assert trx['signatures']
Exemple #5
0
    def start_nodes(self, wait=False):
        self.nodes = []
        if self.log_config:
            configs = f'--data-dir ./{self.tmp_dir}/dd --config-dir ./{self.tmp_dir}/cd -l {self.log_config} {self.extra}'
        else:
            configs = f'--data-dir ./{self.tmp_dir}/dd --config-dir ./{self.tmp_dir}/cd {self.extra}'
        args = f'nodeos --verbose-http-errors  --http-max-response-time-ms 100 --p2p-listen-endpoint {self.host}:9100 {configs} -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin --plugin eosio::history_api_plugin -e --resource-monitor-space-threshold 99 --http-server-address {self.host}:9000 --contracts-console --access-control-allow-origin="*"'  # --backing-store rocksdb'
        logger.info(args)
        args = shlex.split(args)
        # if self.show_log:
        #     f = sys.stdout
        # else:
        #     f = open('log.txt', 'a')
        # f = sys.stdout
        if self.show_log:
            p = subprocess.Popen(args)
        else:
            f = open('log.txt', 'a')
            p = subprocess.Popen(args, stdout=f, stderr=f)

        self.nodes.append(p)

        eosapi.set_node(f'http://{self.host}:9000')
        while True:
            time.sleep(0.5)
            try:
                info = eosapi.get_info()
                # logger.info(info)
                break
            except Exception as e:
                logger.info(e)
        if self.single_node:
            return
        self.producer_keys = [{
            "public":
            "EOS7haGjz9YTepY31iZNfP13dzVXvsU5D2VHeJNZZjhxwMVyCrCFL",
            "private":
            "5Jyj1Scuwu47yTBbQoYojrvw5xbMoUUGHoV4DzEFsKDjAVrvEhB"
        }, {
            "public":
            "EOS5g4kCpZDYHLrbmkGh3cvnbt9KZs9kK3j95LKjRTT8pYR4dkKE3",
            "private":
            "5JrfTriycVJHxnAw2gBEuLXjU2HAqZMwyzw18dNMVfXhkN4vQ4D"
        }, {
            "public":
            "EOS8GGk6a2RU8JCGLEQ4LVhFtMH9PLvcPYrwxviCKr842amwvBWdD",
            "private":
            "5Hxz7hbHK9nJg1kV4W2ScMGFCX6Ks4B8MQ5kt1AdmRNRzxymP5X"
        }, {
            "public":
            "EOS56KkFcZ5rtkSQmM9ZbBRV8fmGzdC3GTGrZi7KuQEhJmHSpiMHg",
            "private":
            "5KLBi386dgBDHunmoqrEbj6MaydYwEXgx1Awqk4a78rZ7b9S7iN"
        }, {
            "public":
            "EOS5cv6rQ1okdvqktfX8R2SKeyMFZAnFHCc1jAXerbpzUtsu4A9F9",
            "private":
            "5JaoiGqLBQ9ASsB946anLJa8hPAm7yaLn4gY1adU7vw9LX8UTtJ"
        }]

        start_port = 9001
        http_ports = [port for port in range(start_port, start_port + 5)]
        p2p_ports = [
            9100,
        ]
        for http_port in http_ports:
            p2p_listen_port = http_port + 100
            index = http_port - start_port
            http_ports_copy = copy.copy(http_ports)
            del http_ports_copy[index]

            bp = f'genesisbp11{index+1}'
            logfile = f'{self.tmp_dir}/{bp}.log'
            pub = self.producer_keys[index]['public']
            priv = self.producer_keys[index]['private']

            signature_provider = f'--signature-provider={pub}=KEY:{priv}'
            http_server_address = f'--http-server-address {self.host}:{http_port}'
            p2p_listen_endpoint = f'--p2p-listen-endpoint {self.host}:{p2p_listen_port}'

            p2p_peer_address = ''
            for port in p2p_ports:
                p2p_peer_address += f'--p2p-peer-address {self.host}:{port} '

            dirs = f'--data-dir {self.tmp_dir}/dd-{bp} --config-dir {self.tmp_dir}/cd-{bp} -p {bp}'
            if http_port == 9001:
                args = f'nodeos -e {dirs} {signature_provider} {http_server_address} {p2p_listen_endpoint} {p2p_peer_address} --verbose-http-errors  --http-max-response-time-ms 100 --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin --plugin eosio::history_api_plugin --resource-monitor-space-threshold 99 --contracts-console --access-control-allow-origin="*"'  # --backing-store rocksdb'
            else:
                args = f'nodeos {dirs} {signature_provider} {http_server_address} {p2p_listen_endpoint} {p2p_peer_address} --verbose-http-errors  --http-max-response-time-ms 100 --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin --plugin eosio::history_api_plugin --resource-monitor-space-threshold 99 --contracts-console --access-control-allow-origin="*"'  # --backing-store rocksdb'

            logger.info(args)
            args = shlex.split(args)

            f = open(logfile, 'a')
            p = subprocess.Popen(args, stdout=f, stderr=f)
            self.nodes.append(p)

            p2p_ports.append(p2p_listen_port)

        if wait:
            p.wait()
        return p
Exemple #6
0
import json
import time
from pyeoskit import eosapi
from pyeoskit import Client

print(eosapi)
info = eosapi.get_info()

if False:
    info = eosapi.get_info()
    print(info)

    block = eosapi.get_block(1)
    print(block)

    state = eosapi.get_block_header_state(info.last_irreversible_block_num)
    print(state)

    account = eosapi.get_account('hello')
    print(account)

    code = eosapi.get_code('hello')
    print(code)

    abi = eosapi.get_abi('hello')
    print(abi)

    abi = eosapi.get_raw_code_and_abi('hello')
    print(abi)

    abi = eosapi.get_raw_abi('hello')
Exemple #7
0
# transfer example

import os
from pyeoskit import eosapi, wallet
#import your account private key here
wallet.import_key('mywallet', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p')

eosapi.set_node('https://api.eosn.io')
info = eosapi.get_info()
print(info)
args = {
    'from': 'test1',
    'to': 'test2',
    'quantity': '1.0000 EOS',
    'memo': 'hello,world'
}
eosapi.push_action('eosio.token', 'transfer', args, {'test1':'active'})