"""
    100 transactions took 77.0 seconds, i.e. 0.770 per transaction.
    --> max bandwidth is 1.3 TPS
    """
    timed = time.time()
    # sign_many_threaded_queue(numTx=20, num_worker_threads=10);
    sign_many_threaded(N=N)
    timed = time.time() - timed
    print("that took %.1f seconds, i.e. %.3f per transaction" %
          (timed, timed / N))


if __name__ == '__main__':
    # print(os_command())
    # test_sign(); exit()

    benchmark_signing_workaround(5)
    exit()

    substrate = substrateinterface.SubstrateInterface(
        url=URL)  # , address_type=42)

    dot = get_balance(substrate, address=BOB_ADDRESS)
    print()

    balance_transfer(dest=BOB_ADDRESS, value=1000000000000, signer='//Alice')
    time.sleep(10)

    print()
    dot = get_balance(substrate, address=BOB_ADDRESS)
'''
Created on 7 Mar 2020

@author: andreas
'''

import substrateinterface

substrate = substrateinterface.SubstrateInterface(url="http://127.0.0.1:9800") # , address_type=42) # "http://127.0.0.1:9933")

PS_EXAMPLE_ADDRESS ='EaG2CRhJWPb7qmdcJvy3LiWdh26Jreu9Dx6R1rXxPmYXoDk'; print (len(PS_EXAMPLE_ADDRESS))
ALICE_ADDRESS =     '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; print (len(ALICE_ADDRESS))
ALICE_PUBKEY =      '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'

"""
subkey inspect //Alice
Secret Key URI `//Alice` is account:
  Secret seed:      0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a
  Public key (hex): 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
  Account ID:       0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
  SS58 Address:     5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
"""


def balance_transfer(dest, value):
    payload = substrate.compose_call(call_module='Balances',
                                     call_function='transfer',
                                     call_params={'dest': dest,
                                                  'value': value})
    print (payload)
#!/usr/bin/env python3
"""
@summary: found an error, reported in https://github.com/polkascan/py-substrate-interface/issues/13

@version: v01 (10/June/2020)
@since:   10/June/2020
@author:  https://github.com/drandreaskrueger
@see:     https://github.com/drandreaskrueger/chainhammer-substrate for updates
"""

# import requests; print(requests.__version__) # example for __version__
import substrateinterface
from pprint import pprint
# import scalecodec
# print (substrateinterface.__version__, scalecodec.__version__)
substrate = substrateinterface.SubstrateInterface(url="ws://127.0.0.1:9944/")
ch = substrate.get_chain_head()
chb = substrate.get_chain_block(ch)
chbn = int(chb['block']['header']['number'], 16)
print("block #%s (%s)" % (chbn, ch))
print(substrate.get_runtime_events(ch))
pprint(substrate.get_runtime_events())
示例#4
0
import substrateinterface as si
import datetime

sub = {
    'substrate_dao':
    si.SubstrateInterface(url="wss://substrate.ipci.io"),
    'substrate_robonomics':
    si.SubstrateInterface(url="wss://vladivostok-rpc.robonomics.network")
}


def get_network_status(substrate):
    network = sub.get(substrate)
    parachain_name = network.rpc_request(method='system_chain',
                                         params=[],
                                         result_handler=None).get('result')

    version = network.rpc_request(method='system_version',
                                  params=[],
                                  result_handler=None).get('result')

    token = network.rpc_request(
        method='system_properties', params=[],
        result_handler=None).get('result')['tokenSymbol']

    peers_count = network.rpc_request(
        method='system_health', params=[],
        result_handler=None).get('result')['peers']

    block_hash = network.get_chain_head()
    block_number = network.get_block_number(block_hash)