-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python SDK不能插入 #196
Comments
我同样测试了给出的TableTest合约,使用如下的python脚本:期望插入一条记录并查询到他: #!/usr/bin/env python
# -*- coding: utf-8 -*-
from client.bcosclient import BcosClient
from client.stattool import StatTool
from client.datatype_parser import DatatypeParser
from client.common.compiler import Compiler
from client_config import client_config
from client.bcoserror import BcosException, BcosError
from client.precompile.crud.crud_service import Table, Entry, CRUDService
from kafka import KafkaConsumer
import traceback
import os
import subprocess
import json
import time
import asyncio
ContractAddr = "0x71790d4d379cb1271f170f3fab891cf49cd02672"
# abi_file = "../console/contracts/TableDemo/"+ ContractAddr+"/TableDemo.abi"
abi_file = "../console/contracts/.compiled/1/TableTest/"+ ContractAddr+"/TableTest.abi"
data_parser = DatatypeParser()
data_parser.load_abi_file(abi_file)
contract_abi = data_parser.contract_abi
try:
client = BcosClient()
print(client.getinfo())
# 尝试进行TableDemo合约的调用
# 表名、主key、值域
print("\n>>Call:------------------------------------------------------------------------")
res = client.call(ContractAddr, contract_abi, "select", ["TEST"])
print("call select:", res)
res = client.call(ContractAddr, contract_abi, "insert",["TEST",2,"juele"])
print("插入记录返回:", res)
res = client.call(ContractAddr, contract_abi, "select", ["TEST"])
print("call select:", res)
client.finish()
except BcosException as e:
print("demo_get failed, BcosException information: {}".format(e))
traceback.print_exc()
except BcosError as e:
print("demo_get failed, BcosError information: {}".format(e))
traceback.print_exc()
except Exception as e:
traceback.print_exc()
client.finish() 以下是返回结果: channel 127.0.0.1:20200,groupid :1,crypto type:ECDSA,ssl type:ECDSA
可以看到插入记录的返回是成功return 1了,但是并无法查询到新增的记录 |
python sdk client的call是对应合约里的只读/查询接口,即view修饰的接口 |
以TableTest.sol 为例,请问是否可以给一个样例?res = client. sendRawTransaction(ContractAddr, contract_abi, "insert",["TEST",2,"juele"])是这样么? |
此外想请问一下是否提供了异步插入的函数? |
call也是会调用合约并返回值的,只是交易不参加共识不会落盘 |
好的 谢谢! |
我根据TableTest.sol写了一个合约,只是把TableTest里的int256类型也换成了string类型,然后使用python SDK去进行合约调用,表现出以下行为:
python 调用部分
合约:
The text was updated successfully, but these errors were encountered: