Ejemplo n.º 1
0
config["default_prefix"] = gph.rpc.chain_params["prefix"] # 向钱包数据库中添加默认信息
config["default_account"] = defaultAccount # 向钱包数据库中添加默认信息

#account test
#pprint(gph.wallet.removeAccount(None))
#pprint(gph.wallet.getAccounts())

#合约创建
#contract_name = "contract.debug.hello"
contract_name = "contract.test1.hello"

data = "function hello() \
    chainhelper:log('Hello World!') \
    chainhelper:log(date('%Y-%m-%dT%H:%M:%S', chainhelper:time())) \
end "
pprint(gph.create_contract(contract_name, data=data, con_authority=pub, account=defaultAccount))

#合约调用: contract.debug.hello
value_list=[]
#pprint(gph.call_contract_function(contract_name, "hello", value_list=value_list, account=defaultAccount))

# 修改合约内容
revise_data = "function hello() \
    chainhelper:log('hello revise contract test. 2019-08-20 11:13:15') \
    chainhelper:log(date('%Y-%m-%dT%H:%M:%S', chainhelper:time())) \
end "
#pprint(gph.revise_contract(contract_name, data=revise_data, account=defaultAccount))


#test result data:
#1. 创建合约
Ejemplo n.º 2
0
if gph.wallet.created() is False:
    gph.newWallet("123456")

#钱包解锁
if gph.wallet.locked() is True:
    gph.wallet.unlock("123456")

#init0 ["COCOS5vzuh6YRRmCjUMeeHLsjnVCdJwqm9WZoUBDDNVp7HTwFM1ZYQT", "5JHdMwsWkEXsMozFrQAQKnKwo44CaV77H45S9PsH7QVbFQngJfw"]
pub = "COCOS5vzuh6YRRmCjUMeeHLsjnVCdJwqm9WZoUBDDNVp7HTwFM1ZYQT"
pprint(gph.wallet.getPrivateKeyForPublicKey(pub))

#合约创建1:单行合约
data1 = "function hello() chainhelper:log('Hello World!') end"
pprint(
    gph.create_contract("contract.pytest.hello",
                        data=data1,
                        con_authority=pub,
                        account="init0"))
'''
执行结果:
tx.buffer>>>: {'extensions': [], 'signatures': ['1f11b53efe5abb9fa5690644b437ce2fe7193b3deeb5bc0f13021241ad914c008019942a45a830253f49410e77537d8739a1f1c629f31938c613085faa8ad82aa9'], 'ref_block_prefix': 695707653, 'ref_block_num': 53573, 'operations': [[43, {'data': "function hello() chainhelper:log('Hello World!') end", 'extensions': [], 'fee': {'asset_id': '1.3.0', 'amount': 2051757}, 'contract_authority': 'COCOS5vzuh6YRRmCjUMeeHLsjnVCdJwqm9WZoUBDDNVp7HTwFM1ZYQT', 'owner': '1.2.4', 'name': 'contract.pytest.hello'}]], 'expiration': '2019-08-21T06:34:07'}
tx======>>: {'extensions': [], 'signatures': ['1f11b53efe5abb9fa5690644b437ce2fe7193b3deeb5bc0f13021241ad914c008019942a45a830253f49410e77537d8739a1f1c629f31938c613085faa8ad82aa9'], 'ref_block_prefix': 695707653, 'ref_block_num': 53573, 'operations': [[43, {'data': "function hello() chainhelper:log('Hello World!') end", 'extensions': [], 'fee': {'asset_id': '1.3.0', 'amount': 2051757}, 'contract_authority': 'COCOS5vzuh6YRRmCjUMeeHLsjnVCdJwqm9WZoUBDDNVp7HTwFM1ZYQT', 'owner': '1.2.4', 'name': 'contract.pytest.hello'}]], 'expiration': '2019-08-21T06:34:07'}
transaction>>>: {'extensions': [], 'signatures': ['1f11b53efe5abb9fa5690644b437ce2fe7193b3deeb5bc0f13021241ad914c008019942a45a830253f49410e77537d8739a1f1c629f31938c613085faa8ad82aa9'], 'ref_block_prefix': 695707653, 'ref_block_num': 53573, 'operations': [[43, {'data': "function hello() chainhelper:log('Hello World!') end", 'extensions': [], 'fee': {'asset_id': '1.3.0', 'amount': 2051757}, 'contract_authority': 'COCOS5vzuh6YRRmCjUMeeHLsjnVCdJwqm9WZoUBDDNVp7HTwFM1ZYQT', 'owner': '1.2.4', 'name': 'contract.pytest.hello'}]], 'expiration': '2019-08-21T06:34:07'}
['66d25d4d1a8fd68fe8d431f1af4b0c11d7d2760777261fc77488033a4c643177',
 {'block': 53574,
  'expiration': '2019-08-21T06:34:07',
  'extensions': [],
  'operation_results': [[2, {'real_running_time': 822, 'result': '1.16.1'}]],
  'operations': [[43,
                  {'contract_authority': 'COCOS5vzuh6YRRmCjUMeeHLsjnVCdJwqm9WZoUBDDNVp7HTwFM1ZYQT',
                   'data': "function hello() chainhelper:log('Hello World!') "
                           'end',