コード例 #1
0
ファイル: __init__.py プロジェクト: openchatproject/safeos
def _set_contract(account, wast_file, abi_file):
    with open(wast_file, 'rb') as f:
        wasm = eosapi.wast2wasm(f.read())

    code_hash = eosapi.sha256(wasm)
    with open(abi_file, 'rb') as f:
        abi = f.read()

    actions = []
    _setcode = eosapi.pack_args('eosio', 'setcode', {
        'account': account,
        'vmtype': 0,
        'vmversion': 0,
        'code': wasm.hex()
    })
    #        _setabi = eosapi.pack_args('eosio', 'setabi', {'account':account, 'abi':abi.hex()})
    _setabi = eosapi.pack_setabi(abi_file, account)

    old_hash = eosapi.get_code_hash(account)
    print(old_hash, code_hash)
    if code_hash != old_hash:
        setcode = ['eosio', 'setcode', _setcode, {account: 'active'}]
        actions.append(setcode)

    setabi = ['eosio', 'setabi', _setabi, {account: 'active'}]
    actions.append(setabi)
    rr, cost = eosapi.push_actions(actions)
    assert_ret(rr)
コード例 #2
0
def t2():
    contracts_path = os.path.join(os.getcwd(), '..', 'contracts')
    sys.path.append(os.getcwd())
    account = 'eosio'
    path = 'eosio.system'
    accounts = gen_names(ACCOUNT_COUNT)

    _path = os.path.join(contracts_path, path, path)
    wast = _path + '.wast'
    abi_file = _path + '.abi'

    with open(wast, 'rb') as f:
        wasm = eosapi.wast2wasm(f.read())
    code_hash = eosapi.sha256(wasm)
    with open(abi_file, 'rb') as f:
        abi = f.read()

    for account in accounts:
        _create_account(account)
        continue
        if not eosapi.get_account(account):
            _create_account(account)

    for account in accounts:
        print('+++++++++code update', account)
        actions = []
        _setcode = eosapi.pack_args('eosio', 'setcode', {
            'account': account,
            'vmtype': 0,
            'vmversion': 0,
            'code': wasm.hex()
        })
        #        _setabi = eosapi.pack_args('eosio', 'setabi', {'account':account, 'abi':abi.hex()})
        _setabi = pack_setabi(abi_file, account)

        old_hash = eosapi.get_code_hash(account)
        print(old_hash, code_hash)
        if code_hash != old_hash:
            setcode = ['eosio', 'setcode', _setcode, {account: 'active'}]
            actions.append(setcode)

        setabi = ['eosio', 'setabi', _setabi, {account: 'active'}]
        actions.append(setabi)
        rr, cost = eosapi.push_actions(actions)
        assert_ret(rr)
コード例 #3
0
def publish_system_contracts(accounts_map):
    contracts_path = os.path.join(os.getcwd(), '..', 'contracts')
    sys.path.append(os.getcwd())
    #    accounts_map = {'eosio.token':'eosio.token', 'eosio.msig':'eosio.msig', 'eosio':'eosio.system'}
    for account in accounts_map:
        print('account', account)
        if not eosapi.get_account(account):
            r = eosapi.create_account('eosio', account, key1, key2)
            assert r

        _path = os.path.join(contracts_path, accounts_map[account],
                             accounts_map[account])
        wast = _path + '.wast'
        code = open(wast, 'rb').read()
        code = eosapi.wast2wasm(code)
        hash = eosapi.sha256(code)
        old_hash = eosapi.get_code_hash(account)
        if old_hash != hash:
            print('+++++++++code update', account)
            wast = _path + '.wast'
            abi = _path + '.abi'
            r = eosapi.set_contract(account, wast, abi, 0)
            print(wast, abi)
            time.sleep(1.0)
            if account == 'eosio.token' and eosapi.get_balance('eosio') <= 0.0:
                print('issue system token...')
                #                msg = {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS","can_freeze":0,"can_recall":0, "can_whitelist":0}
                msg = {
                    "issuer": "eosio",
                    "maximum_supply": "11000000000000.0000 EOS"
                }
                r = eosapi.push_action('eosio.token', 'create', msg,
                                       {'eosio.token': 'active'})
                assert r
                r = eosapi.push_action(
                    'eosio.token', 'issue', {
                        "to": "eosio",
                        "quantity": "10000000000000.0000 EOS",
                        "memo": ""
                    }, {'eosio': 'active'})
                assert r
コード例 #4
0
def prepare(account, src, abi, full_src_path, code_type = None):
    _src_dir = os.path.dirname(os.path.abspath(full_src_path))
    if not code_type:
        if src.endswith('.wast'):
            code_type = CODE_TYPE_WAST
        elif src.endswith('.py'):
            code_type = CODE_TYPE_PY
        else:
            raise Exception('unknown code type')

    if code_type == 0:
        cpp2wast.set_src_path(_src_dir)
        cpp_src_file = src.replace('.wast', '.cpp')
        if not cpp2wast.build(cpp_src_file):
            raise Exception("build {0} failed".format(cpp_src_file))

    if src.find('/') < 0:
        src = os.path.join(_src_dir, src)

    if abi and abi.find('/') < 0:
        abi = os.path.join(_src_dir, abi)


    if not eosapi.get_account(account):
        print('*'*20, 'create_account')
        _create_account(account)

    with open(src, 'rb') as f:
        code = f.read()
    if code_type == CODE_TYPE_WAST:
        code = eosapi.wast2wasm(code)

    code_hash = eosapi.sha256(code)
    old_hash = eosapi.get_code_hash(account)
    if code_hash != old_hash:
        print('Updating contract', src)
        if code_type == 0:
            _set_contract(account, src, abi)
        else:
            r = eosapi.set_contract(account, src, abi, code_type)
            assert r, 'set_contract failed'