Giter Site home page Giter Site logo

Python SDK不能插入 about python-sdk HOT 6 CLOSED

fisco-bcos avatar fisco-bcos commented on August 23, 2024
Python SDK不能插入

from python-sdk.

Comments (6)

lcy1317 avatar lcy1317 commented on August 23, 2024

我同样测试了给出的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.

coderkentzhang avatar coderkentzhang commented on August 23, 2024

python sdk client的call是对应合约里的只读/查询接口,即view修饰的接口
插入数据应该用 sendRawTransaction 接口

from python-sdk.

lcy1317 avatar lcy1317 commented on August 23, 2024

以TableTest.sol 为例,请问是否可以给一个样例?res = client. sendRawTransaction(ContractAddr, contract_abi, "insert",["TEST",2,"juele"])是这样么?
以及想请问一下为什么使用client.call 他会提供返回值呢?

from python-sdk.

lcy1317 avatar lcy1317 commented on August 23, 2024

此外想请问一下是否提供了异步插入的函数?

from python-sdk.

coderkentzhang avatar coderkentzhang commented on August 23, 2024

call也是会调用合约并返回值的,只是交易不参加共识不会落盘
sendRawTransaction本身是异步的,sendRawTransaction之后getTransactionReceipt获取最终结果,
sendRawTransactionAndGetReceipt才是同步的。
参数列表和call类似,有一些用不到的参数留空就行了

from python-sdk.

lcy1317 avatar lcy1317 commented on August 23, 2024

好的 谢谢!

from python-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.