Comments (6)
我同样测试了给出的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
Call:------------------------------------------------------------------------
call select: (('TEST',), (1,), ('woliekai',))
插入记录返回: (1,)
call select: (('TEST',), (1,), ('woliekai',))
可以看到插入记录的返回是成功return 1了,但是并无法查询到新增的记录
from python-sdk.
python sdk client的call是对应合约里的只读/查询接口,即view修饰的接口
插入数据应该用 sendRawTransaction 接口
from python-sdk.
以TableTest.sol 为例,请问是否可以给一个样例?res = client. sendRawTransaction(ContractAddr, contract_abi, "insert",["TEST",2,"juele"])是这样么?
以及想请问一下为什么使用client.call 他会提供返回值呢?
from python-sdk.
此外想请问一下是否提供了异步插入的函数?
from python-sdk.
call也是会调用合约并返回值的,只是交易不参加共识不会落盘
sendRawTransaction本身是异步的,sendRawTransaction之后getTransactionReceipt获取最终结果,
sendRawTransactionAndGetReceipt才是同步的。
参数列表和call类似,有一些用不到的参数留空就行了
from python-sdk.
好的 谢谢!
from python-sdk.
Related Issues (20)
- [parsimonious 合适版本问题] 当前版本的Python-sdk 在合约调用的参数解析,以及对节点返回结果的解析都存在问题。 HOT 2
- 【新版合约部署问题】合约部署报错信息有未安装的环境 HOT 2
- python-sdk 跑demo_get.py报错 HOT 9
- 使用过程的报错 HOT 6
- 也请更新(升级)Python_SDK 所依赖 solc (Solidity 编译器) HOT 1
- 执行pip install -r requirements.txt 命令报错 HOT 2
- win10 安装python-sdk报错 HOT 2
- console2.py执行报错 HOT 1
- 部署合约提示错误 HOT 2
- linux 环境下 账户pem无法读取 HOT 9
- console3.py CONSENSUS cmd error HOT 3
- 部署合约出现问题 HOT 1
- 运行demo代码时出现问题 HOT 1
- 部署了contracts文件夹下的KVTableTest合约,发起交易失败 HOT 4
- 运行testclient.py报错 HOT 1
- 代码有错误 HOT 1
- parsimonious库有冲突 HOT 1
- console2.py execute rpc command error HOT 1
- Smart contract error not returned HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-sdk.