Code Monkey home page Code Monkey logo

xuper-sdk-go's Introduction

XuperChain

Build Status Go Report Card GolangCI License Release

中文 | English


What is XuperChain

XuperChain, the first open source project of XuperChain Lab, introduces an underlying solution to build the super alliance network, based on the dynamic kernel of xupercore. You can use xuperchain as a blockchain infrastructure to build a compliant blockchain network.

XuperChain is the underlying solution for union networks with following highlight features:

  • Dynamic kernel

    • Based on the dynamic kernel technology, the free extension kernel components without kernel code intrusion and lightweight extension customized kernel engine are implemented to meet the needs of blockchain implementation for various scenarios.
    • It provides a comprehensive and high-performance implementation of standard kernel components.
    • Comprehensively reduce the cost of blockchain research and development, and open a new era of one click chain development.
  • High Performance

    • Creative XuperModel technology makes contract execution and verification run parallel.
    • TDPoS ensures quick consensus in a large scale network.
    • WASM VM using AOT technology.
  • Solid Security

    • Contract account protected by multiple private keys ensures assets safety.
    • Flexible authorization system supports weight threshold, AK sets and could be easily extended.
  • High Scalability

    • Robust P2P network supports a large scale network with thousands of nodes.
    • Branch management on ledger makes automatic convergence consistency and supports global deployment.
  • Multi-Language Support: Support pluggable multi-language contract VM using XuperBridge technology.

  • Flexibility: Modular and pluggable design provides high flexibility for users to build their blockchain solutions for various business scenarios.

Quick start

Requirements

  • OS Support: Linux and Mac OS
  • Go 1.14.x or later
  • GCC 4.8.x or later
  • Git

Build

Clone the repository

git clone https://github.com/xuperchain/xuperchain

Note:

master branch contains the latest features but might be unstable.

For production use, please check out the latest release.

Enter the xuperchain folder and build the code:

cd xuperchain
make

Note that if you are using Go 1.11 or later, go modules are used to download 3rd-party dependencies by default. You can also disable go modules and use the prepared dependencies under vendor folder.

Run test:

make test

Run

Run single node blockchain

There is an output folder if build successfully. Enter the output folder, create a default chain & start blockchains:

cd ./output
sh control.sh start

By doing this, a blockchain named "xuper" is created, you can find the data of this blockchain at ./data/blockchain/xuper/.

By default, the xuper chain will produce a block every 3 seconds, try the following command to see the trunkHeight of chain and make sure it's growing.

./bin/xchain-cli status

Run multi nodes blockchain

Generate multi nodes. Before running the following command, make sure you have run make to make the code.

make testnet

Enter the testnet directory, and then start three nodes separately (make sure the port is not used)

cd ./testnet/node1
sh ./control.sh start
cd ../node2
sh ./control.sh start
cd ../node3
sh ./control.sh start

Observe the status of each node

./bin/xchain-cli status -H :37101
./bin/xchain-cli status -H :37102
./bin/xchain-cli status -H :37103

Documentation

We have new documentation of Chinese version at XuperChain Chinese Docs, the English version is coming soon.

How to Contribute

We encourage you to contribute to XuperChain.

Please review the Contribution guidelines for information on how to get started contributing to the project.

License

XuperChain is under the Apache License, Version 2.0.

Contact

For business cooperation, please email:[email protected] (Note with source: GitHub)。

If you are interested in the open source technology and application of XuperChain, welcome to add 百度超级链·小助手 in WeChat, join the Baidu Super Chain Developer Community by replying 技术论坛进群, and have in-depth exchanges with Baidu senior engineers!

WeChat QR code is as follows: 496bd829f51cda8f4c8027daf0e6b543

xuper-sdk-go's People

Contributors

chenfengjin avatar codecmn avatar gaoweibupt avatar godeamon avatar hawkjing avatar michellez avatar preminem avatar qizheng09 avatar six-days avatar superlitian avatar tri-stone avatar yucaowang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xuper-sdk-go's Issues

合约并发调用时会报错

测试代码:

func TestInvokeWasmContract2(t *testing.T) {
	acc, _ := account.RetrieveAccount(mnemonic, 1)
	wasmContract := InitWasmContract(acc, node, "xuper", "counter", "XC1111111111111111@xuper")

	wg := &sync.WaitGroup{}
	for i := 0; i < 4; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			txid, err := wasmContract.InvokeWasmContract("increase", map[string]string{"key": "counter"})
			if err != nil {
				t.Log("err:", err)
				return
			}
			t.Log("txid:", txid)
		}()
	}
	wg.Wait()
}

错误:

--- PASS: TestInvokeWasmContract2 (3.82s)
    contract_test.go:191: txid: 958bdd5540491fb90707cecd2b07febb3523a1762cdbd86f2a53a07700d3bd4a
    contract_test.go:188: err: Failed to post tx: UTXOVM_NOT_FOUND_ERROR
    contract_test.go:188: err: Failed to post tx: UTXOVM_NOT_FOUND_ERROR
    contract_test.go:188: err: Failed to post tx: UTXOVM_NOT_FOUND_ERROR

XuperChain使用Go-SDK调用模板合约“文件hash上链时,更改文件hash_id后仍出现”such hash has existed already的报错

XuperChain使用Go-SDK调用模板合约“文件hash上链时,更改文件hash_id后仍出现”such hash has existed already的报错
image
我在“工作台”中“合约管理”中调用中修改不同的hash_id均成功了,但是在本地调用时修改不同的hash_id出现了such hash has existed already的报错
智能合约中的存证函数如下:
void storeFileInfo() {
xchain::Context* ctx = this->context();
std::string user_id = ctx->arg("user_id");
std::string hash_id = ctx->arg("hash_id");
std::string file_name = ctx->arg("file_name");
const std::string userKey = UserBucket + "/" + user_id + "/" + hash_id;
const std::string hashKey = HashBucket + "/" + hash_id;
std::string value = user_id + "\t" + hash_id + "\t" + file_name;
std::string tempVal;
if (ctx->get_object(hashKey, &tempVal)) {
ctx->error("storeFileInfo failed, such hash has existed already");
return;
}
if (ctx->put_object(userKey, value) && ctx->put_object(hashKey, value)) {
ctx->ok("storeFileInfo success");
return;
}
ctx->error("storeFileInfo failed");
}
后续更新:
去除了智能合约中的唯一性约束代码:
if (ctx->get_object(hashKey, &tempVal)) {
ctx->error("storeFileInfo failed, such hash has existed already");
return;
多次使用不同的hash_id运行成功,两次使用相同的hash_id上链存储也成功运行。但是实际的区块链存证业务场景中要求对存证文件的唯一性约束,请问错误是处在SDK上还是智能合约上?

not support "nofee"

xchain.go

	utxoOutput := &pb.UtxoOutput{
		//		UtxoList: utxolist,
		//		TotalSelected: totalSelected.String(),
		UtxoList:      response.UtxoOutput.UtxoList,
		TotalSelected: response.UtxoOutput.TotalSelected,

"response.UtxoOutput" will be nil when invoke contract

error message

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xaa2475]

goroutine 1 [running]:
github.com/xuperchain/xuper-sdk-go/xchain.(*Xchain).GenRealTxOnly(0xc00026c010, 0xc0002967d0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/root/go/pkg/mod/github.com/xuperchain/[email protected]/xchain/xchain.go:479 +0xa5
github.com/xuperchain/xuper-sdk-go/xchain.(*Xchain).GenCompleteTxAndPost(0xc00026c010, 0xc0002967d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/root/go/pkg/mod/github.com/xuperchain/[email protected]/xchain/xchain.go:745 +0x1097
github.com/xuperchain/xuper-sdk-go/contract.(*WasmContract).PostWasmContract(0xc00026c000, 0xc0002967d0, 0x0, 0x0, 0x0, 0x0)
	/root/go/pkg/mod/github.com/xuperchain/[email protected]/contract/contract.go:120 +0x416
github.com/xuperchain/xuper-sdk-go/contract.(*WasmContract).InvokeWasmContract(0xc00026c000, 0xbf6580, 0x8, 0xc0001a3e48, 0x0, 0x0, 0x0, 0x0)
	/root/go/pkg/mod/github.com/xuperchain/[email protected]/contract/contract.go:132 +0x205

go sdk编译失败

make失败,go get github.com/xuperchain/xuper-sdk-go/v2 这个网址404

如何判断一笔交易已经上链

SDK版本

v2.0.0

问题描述

我想通过TxId查询判断当前这一笔交易有没有上链,但QueryTxByID()没有返回相关状态值。看下代码,貌似是有实现的但是并没有暴露出来。
x1
QueryTx方法返回的是TxStatus结构体对象
x2
对应的枚举值
x3

不知道我的猜想是否正确,有没有什么方案?感谢!

没有evm合约升级方法

请问有evm合约升级方法吗,我看sdk中只提供了native和wasm合约升级方法,另外通过解读源码发现,提示说关闭了evm升级,不知为何?

调用智能合约时失败了

报错:panic: EndorserCall PreExecWithFee failed: rpc error: code = Unknown desc = error 17 - Error 17: execution reverted: execution reverted
sdk.yaml设置如下:

endorseServiceHost: "39.156.69.83:37100"
complianceCheck:
isNeedComplianceCheck: true
isNeedComplianceCheckFee: true
complianceCheckEndorseServiceFee: 400
complianceCheckEndorseServiceFeeAddr: aB2hpHnTBDxko3UoP2BpBZRujwhdcAFoT
complianceCheckEndorseServiceAddr: jknGxa6eyum1JrATWvSJKW3thJ9GKHA9n
minNewChainAmount: "100"
crypto: "xchain"
txVersion: 3
maxRecvMsgSize: 134217728

执行main.go 中的 testContractAccount() 报错

节点是拉的最新的代码 master 分支,配置成xpoa共识,返回报未实现?
retrieveAccount address: nuSMPvo6UUoTaT8mMQmHbfiRbJNbAymGh
2020/10/24 17:02:08 PreExecWithSelecUTXO EndorserCall failed, err: rpc error: code = Unimplemented desc = unknown service pb.xendorser
2020/10/24 17:02:08 CreateContractAccount err: EndorserCall error! Response is: rpc error: code = Unimplemented desc = unknown service pb.xendorser
exit status 255

查询区块Proposer的一些疑问

SDK版本:0.2.0

Xchain 版本:5.1.0

使用Go SDK查询区块的Proposer返回有问题,请问是我解析的有问题还是返回的内容不正确,其他参数(PreHash 等)暂时没问题。
Screenshot 2022-05-30 17-43-58

RWACL_INVALID_ERROR

2021/01/18 09:03:09 start testDeployWasmContract......
W8GDt7ajEP4rh18FAgw7xnQg2P6Wg8BTh
account: &{W8GDt7ajEP4rh18FAgw7xnQg2P6Wg8BTh {"Curvname":"P-256","X":115647121523999615544642610898155919161143807124137510426248196191719673759457,"Y":6834714425167762045798660276280535385884829351045282705119506064327324275863,"D":83942495777393029042150863703958248121731008811406779280150121616048053996456} {"Curvname":"P-256","X":115647121523999615544642610898155919161143807124137510426248196191719673759457,"Y":6834714425167762045798660276280535385884829351045282705119506064327324275863} }
2021/01/18 09:03:16 Fee will cost: 171785
2021/01/18 09:03:16 contract response: initialize succeed
2021/01/18 09:03:16 ComplianceCheck txid: f3290e93d43354ed9213f4be49548ae317408080d0abe98ce0b63a540dcd45b4
2021/01/18 09:03:16 DeployWasmContract err: Failed to post tx: RWACL_INVALID_ERROR
panic: Failed to post tx: RWACL_INVALID_ERROR

运行main_trust_counter时遇到上面的问题,这个错误是怎么会是

合约event问题

请问:
1.调用合约返回信息中没有eventlog,那有办法在不使用订阅的情况下知道此次交易是否有eventlog吗?
2.我想同步非挖矿的交易信息,如果使用订阅所有块,返回的信息中只有交易hash,并不能区分出这个交易是出块奖励还是正常的交易,这个有办法吗?

proto message 与fabric重名,无法与fabric在同一个项目中编译

github.com/xuperchain/[email protected]/protos/event.pb.go 代码:
func init() {
proto.RegisterEnum("protos.SubscribeType", SubscribeType_name, SubscribeType_value)
proto.RegisterType((*SubscribeRequest)(nil), "protos.SubscribeRequest")
proto.RegisterType((*Event)(nil), "protos.Event")
proto.RegisterType((*BlockRange)(nil), "protos.BlockRange")
proto.RegisterType((*BlockFilter)(nil), "protos.BlockFilter")
proto.RegisterType((*FilteredBlock)(nil), "protos.FilteredBlock")
proto.RegisterType((*FilteredTransaction)(nil), "protos.FilteredTransaction")
}

github.com/hyperledger/fabric-protos-go/blob/release-2.2/peer/events.pb.go 代码:
func init() {
proto.RegisterType((*FilteredBlock)(nil), "protos.FilteredBlock")
proto.RegisterType((*FilteredTransaction)(nil), "protos.FilteredTransaction")
proto.RegisterType((*FilteredTransactionActions)(nil), "protos.FilteredTransactionActions")
proto.RegisterType((*FilteredChaincodeAction)(nil), "protos.FilteredChaincodeAction")
proto.RegisterType((*BlockAndPrivateData)(nil), "protos.BlockAndPrivateData")
proto.RegisterMapType((map[uint64]*rwset.TxPvtReadWriteSet)(nil), "protos.BlockAndPrivateData.PrivateDataMapEntry")
proto.RegisterType((*DeliverResponse)(nil), "protos.DeliverResponse")
}

其中protos.FilteredBlock,protos.FilteredTransaction重复,导致编译后运行直接panic

调用智能合约函数时报错

之前用sdk v1.0.0做成功了,请问v2.0.0是否支持与开放网络部署的智能合约建立连接?
遇到报错如下

EndorserCall ComplianceCheck failed: rpc error: code = Unknown desc = fee not enough

合约调用错误问题

请问,在调用合约得时候出现了这个错误:

image

请问是什么原因呢?

另外我看这个错误17 对应得枚举值为 XChainErrorEnum_ROOT_BLOCK_EXIST_ERROR 请问是不是这个枚举值呢?如何是什么情况下会出现这个错?

image

`普通账号`给`合约账号`转账出现:TX_VERIFICATION_ERROR错误

场景:

  1. 使用的链地址(39.156.69.83:37100)
  2. 本来想通过SDK部署本地编译的solidity合约到链上,提示合约账号UTXO不足;
  3. 所以尝试通过普通账号合约账号转账一些,结果出现TX_VERIFICATION_ERROR的错误?

这个合约账号普通账号下的。

请问是什么原因?

合约部署消耗fee&gas的问题

请问
在合约部署的时候,我们消耗的gas&fee是使用普通账户里面的资产还是合约账户的资产?另外sdk中option有指定消耗资产选项WithFeeFromAccount(),如果不指定该选项,潜在意思是不是说消耗的资产是使用普通账户的资产?
image

rpc error: code = Unknown desc = Err:500-50404-submit tx failed+err:this utxo can not be found

版本

  • go 1.17
  • sdk v2.0.0
  • chain 5.1.x

问题

我使用 xuper-sdk-go/v2 10次并发调用evm合约出现错误rpc error: code = Unknown desc = Err:500-50404-submit tx failed+err:this utxo can not be found,另外这10次调用key value值都不一样,合约方法很简单就是单纯得set值.另外我这也没有出现读写集错误问题,请问如何解决此问题?

调用参数内容:
image

调用返回错误值:
image

ps: 错误值前半部是业务拼接得错误描述

订阅如何拿到solidity抛出的emit数据?

请问
我使用订阅事件功能,我订阅solidity合约如何拿到emit抛出的数据内容?合约内容大概如下
image
对应event定义
image

然后下面的是对应订阅收到的数据内容
image

请问body里面的数据是对应我emit抛出的数据么?如果是我该怎么解析?

编译后执行example/main.go中testTransfer报错

账户余额查询正确,执行transfer报错,错误信息如下:

2020/08/05 15:58:44 PreExecWithSelecUTXO EndorserCall failed, err: rpc error: code = DeadlineExceeded desc = context deadline exceeded
2020/08/05 15:58:44 Transfer PreExecWithSelecUTXO failed, err: EndorserCall error! Response is: rpc error: code = DeadlineExceeded desc = context deadline exceeded
Transfer err: EndorserCall error! Response is: rpc error: code = DeadlineExceeded desc = context deadline exceeded
transfer tx:

合约查询,返回结果与cli命令结果不一致

solidity代码如下:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/// @Custom:security-contact [email protected]
contract Seatune is ERC20, Pausable, Ownable {
constructor() ERC20("Seatune", "TUN") {
_mint(msg.sender, 990000 * 10 ** decimals());
}

function pause() public onlyOwner {
    _pause();
}

function unpause() public onlyOwner {
    _unpause();
}

function mint(address to, uint256 amount) public onlyOwner {
    _mint(to, amount);
}

function _beforeTokenTransfer(address from, address to, uint256 amount)
    internal
    whenNotPaused
    override
{
    super._beforeTokenTransfer(from, to, amount);
}

}
当我执行继承自openzeppelin包的方法时,如果xuperIDE调试,结果如下:
image
如果用cli调用,也是一致的
image
唯独在调用sdk时,返回结果不一致,是一串代码
image
返回的结果是这样的
image

请问如何才能取到正确的返回数据?

make test 报错

make 成功了,但 make test 的时候报以下错误
go test github.com/xuperchain/xuper-sdk-go/account
ok github.com/xuperchain/xuper-sdk-go/account 0.030s
go test github.com/xuperchain/xuper-sdk-go/transfer
ok github.com/xuperchain/xuper-sdk-go/transfer (cached)
go test github.com/xuperchain/xuper-sdk-go/common
ok github.com/xuperchain/xuper-sdk-go/common (cached)
go test github.com/xuperchain/xuper-sdk-go/contract_account
ok github.com/xuperchain/xuper-sdk-go/contract_account (cached)
go test github.com/xuperchain/xuper-sdk-go/contract
ok github.com/xuperchain/xuper-sdk-go/contract (cached)
go test github.com/xuperchain/xuper-sdk-go/xchain

github.com/xuperchain/xuper-sdk-go/xchain [github.com/xuperchain/xuper-sdk-go/xchain.test]

xchain/xchain_test.go:41:5: cli.Amount undefined (type *Xchain has no field or method Amount)
xchain/xchain_test.go:43:5: cli.To undefined (type *Xchain has no field or method To)
xchain/xchain_test.go:55:40: cli.Amount undefined (type *Xchain has no field or method Amount)
xchain/xchain_test.go:81:26: not enough arguments in call to cli.GenRealTx
have (*pb.PreExecWithSelectUTXOResponse, *pb.Transaction)
want (*pb.PreExecWithSelectUTXOResponse, *pb.Transaction, string)
xchain/xchain_test.go:92:6: assignment mismatch: 1 variable but cli.PostTx returns 2 values
xchain/xchain_test.go:104:5: cli.Amount undefined (type *Xchain has no field or method Amount)
xchain/xchain_test.go:106:5: cli.To undefined (type *Xchain has no field or method To)
xchain/xchain_test.go:118:40: cli.Amount undefined (type *Xchain has no field or method Amount)
xchain/xchain_test.go:143:44: cli.To undefined (type *Xchain has no field or method To)
xchain/xchain_test.go:143:52: cli.Amount undefined (type *Xchain has no field or method Amount)
xchain/xchain_test.go:143:52: too many errors
FAIL github.com/xuperchain/xuper-sdk-go/xchain [build failed]
FAIL
Makefile:20: recipe for target 'test' failed
make: *** [test] Error 2

无法调用国密环境

链接本地国密环境时sdk报错:[SM2-P-256] is not supported yet

另:使用注释方法GetCryptoClient() base.CryptoClient出现以下编译异常信息:

# github.com/xuperchain/xuper-sdk-go/account
..\account\account.go:32:27: ecdsaAccount.JsonPublicKey undefined (type *"github.com/xuperchain/xuperchain/core/crypto/account".ECDSAAccount has no field or method JsonPublicKey, but does have JSONPublicKey)
..\account\account.go:33:27: ecdsaAccount.JsonPrivateKey undefined (type *"github.com/xuperchain/xuperchain/core/crypto/account".ECDSAAccount has no field or method JsonPrivateKey, but does have JSONPrivateKey)
..\account\account.go:48:27: ecdsaAccount.JsonPublicKey undefined (type *"github.com/xuperchain/xuperchain/core/crypto/account".ECDSAAccount has no field or method JsonPublicKey, but does have JSONPublicKey)
..\account\account.go:49:27: ecdsaAccount.JsonPrivateKey undefined (type *"github.com/xuperchain/xuperchain/core/crypto/account".ECDSAAccount has no field or method JsonPrivateKey, but does have JSONPrivateKey)
..\account\account.go:75:27: ecdsaAccount.JsonPublicKey undefined (type *"github.com/xuperchain/xuperchain/core/crypto/account".ECDSAAccount has no field or method JsonPublicKey, but does have JSONPublicKey)
..\account\account.go:76:27: ecdsaAccount.JsonPrivateKey undefined (type *"github.com/xuperchain/xuperchain/core/crypto/account".ECDSAAccount has no field or method JsonPrivateKey, but does have JSONPrivateKey)
..\account\account.go:91:40: cryptoClient.GetEcdsaPrivateKeyJsonFormatStr undefined (type base.CryptoClient has no field or method GetEcdsaPrivateKeyJsonFormatStr)
..\account\account.go:95:39: cryptoClient.GetEcdsaPublicKeyJsonFormatStr undefined (type base.CryptoClient has no field or method GetEcdsaPublicKeyJsonFormatStr)
# github.com/xuperchain/xuper-sdk-go/txhash
..\txhash\txhash.go:20:22: cryptoClient.HashUsingDoubleSha256 undefined (type base.CryptoClient has no field or method HashUsingDoubleSha256)
..\txhash\txhash.go:34:24: cryptoClient.HashUsingDoubleSha256 undefined (type base.CryptoClient has no field or method HashUsingDoubleSha256)

EndorserCall error! Response is: rpc error: code = Unimplemented desc = unknown service pb.xendorser

请教一下,我现在操作3.7版本的链需要支持,调用合约,安装合约等操作都会出现以下类似的错误,请问怎么解决呢?

出现的错误:

2022/02/18 17:40:48 GetConfig: &{************:37101 {false false 400 aB2hpHnTBDxko3UoP2BpBZRujwhdcAFoT jknGxa6eyum1JrATWvSJKW3thJ9GKHA9n} 100 xchain}
2022/02/18 17:40:48 PreExecWithSelecUTXO EndorserCall failed, err: rpc error: code = Unimplemented desc = unknown service pb.xendorser
2022/02/18 17:40:48 DeployWasmContract preExe failed, err: EndorserCall error! Response is: rpc error: code = Unimplemented desc = unknown service pb.xendorser
panic: EndorserCall error! Response is: rpc error: code = Unimplemented desc = unknown service pb.xendorser

另外我的skd配置内容如下,也没有配置xendorser开关什么的

endorseServiceHost: "*************"

complianceCheck:
  # 是否需要进行合规性背书
  isNeedComplianceCheck: false
  # 是否需要支付合规性背书费用
  isNeedComplianceCheckFee: false
  # 合规性背书费用
  complianceCheckEndorseServiceFee: 400
  # 支付合规性背书费用的收款地址
  complianceCheckEndorseServiceFeeAddr: aB2hpHnTBDxko3UoP2BpBZRujwhdcAFoT
  # 如果通过合规性检查,签发认证签名的地址
  complianceCheckEndorseServiceAddr: jknGxa6eyum1JrATWvSJKW3thJ9GKHA9n
#创建平行链所需要的最低费用
minNewChainAmount: "100"

# sdk调用生成账号相关的密码类型.简单来说生成的是否是国密算法。
crypto: "xchain"
txVersion: 1

我链的配置如下 xchain.yaml内容如下

# node config
# 日志配置
log:
  # 模块名称
  module: xchain
  # 日志目录
  filepath: logs
  # 日志文件名
  filename: xchain
  fmt: logfmt
  # 是否打印命令行工具端口
  console: true
  # 日志等级
  level: debug

# RPC 服务暴露的端口
tcpServer:
  port: :37101
  # prometheus监控指标端口, 为空的话就不启动
  metricPort: :37200
  tls: false
  #cachePeriod: 2
  # 最大接受数据包长度

# 区块链节点配置
p2p:
  # module is the name of p2p module plugin, value is [p2pv2/p2pv1], default is p2pv2
  module: p2pv2
  port: 47101
  #certPath: ./data/tls/1
  #serviceName: saas_test.server.com
  #bootNodes:
  #  - "/ip4/<ip>/tcp/<port>/p2p/<node_hash>" for p2pv2 or - "<ip>:<port>" for p2pv1
  #staticNodes:
  #  xuper:
  #    - "127.0.0.1:47102"

miner:
  # 密钥存储路径
  keypath: ./data/keys

# 数据存储路径
datapath: ./data/blockchain

# 多盘存储的路径
#datapathOthers:
#    - /ssd1/blockchain
#    - /ssd2/blockchain
#    - /ssd3/blockchain

utxo:
  # utxo的内存LRUCache大小,表示内存中最多缓存多少个UtxoItem
  cachesize: 2000000
  # GenerateTx的临时锁定期限,默认是60秒
  tmplockSeconds: 60
  #单个块的合约执行的总时间(单位ms)
  contractExecutionTime: 500

kernel:
  # minNewChainAmount 设置创建平行链时最少要转多少钱到同链名address
  minNewChainAmount: "100"
  newChainWhiteList:
    - dpzuVdosQrF2kmzumhVeFQZa1aYcdgFpN: true

# 管理native合约的配置
native:
  enable: false
  # 与部署相关的配置
  deploy:
    # 部署白名单,列表为钱包地址
    whiteList:
      enable: false
      addresses:
        - dpzuVdosQrF2kmzumhVeFQZa1aYcdgFpN

  # docker相关配置
  docker:
    enable: false
    # 合约运行的镜像名字
    imageName: "docker.io/centos:7.5.1804"
    # cpu核数限制,可以为小数
    cpus: 1
    # 内存大小限制
    memory: "1G"

  # 停止合约的等待秒数,超时强制杀死
  stopTimeout: 3

# 插件配置文件路径
pluginConfPath: "./conf/plugins.conf"

# 是否启用p2p核心节点直连
coreConnection: false

txidCacheExpiredTime: "10s"

# 是否压缩交易/区块
enableCompress: true

# 块广播模式
blockBroadcaseMode: 0

# 剪枝配置
prune:
  switch: false
  bcname: "xuper"
  targetBlockid: "xxx"

# wasm合约配置

wasm:
  driver: "xvm"
  enableUpgrade: false
  xvm:
    optLevel: 0

# 是否开启默认的XEndorser背书服务
enableXEndorser: false

我是用v2和v1.1版本的sdk都不行,恳求帮助

Remove crypto so dependency from go-sdk

If a user want to use other languages that he is very good at to interact with our blockchain, he'll can use it in the following ways:

  1. He can user our lib that we'll provide in the future
  2. Develop his API by the language that he use

If we don't add this function, a user can't use our lib directly.

support GM

update the version of the dependency of xchain

有啥方法可以查询出合约对应得module类型?

在使用sdk有这样的场景,有人部署了一个native go得合约,或者我忘记了,现在我想调用这个合约,但是我不知道这个合约是什么类型,现在我用别得类型比如InvokeEVMContract() 方法去调用这个go合约就会出错,请问我如何能拿到合约module类型,如果没有可否考虑在QueryAddressContracts()方法或者QueryAccountContracts()方法中进行扩展?

image

sdk在无币模式下,部署和调用合约会触发空指针异常

sdk在无币模式下,部署和调用合约会触发空指针异常

// GenerateTxInput generate txinput part
func (xc *Xchain) GenerateTxInput(utxoOutputs *pb.UtxoOutput, totalNeed *big.Int) (
	[]*pb.TxInput, *pb.TxOutput, error) {
	// utxoList => TxInput
	//
	// gen txInputs
	var txInputs []*pb.TxInput
	var txOutput *pb.TxOutput

        //utxoOutputs是空对象
	for _, utxo := range utxoOutputs.UtxoList {
		txInput := &pb.TxInput{}
		txInput.RefTxid = utxo.RefTxid
		txInput.RefOffset = utxo.RefOffset
		txInput.FromAddr = utxo.ToAddr
		txInput.Amount = utxo.Amount
		txInputs = append(txInputs, txInput)
	}
}

错误描述

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x90c047]

goroutine 6 [running]:
testing.tRunner.func1(0xc0000f2300)
	/usr/local/go/src/testing/testing.go:874 +0x3a3
panic(0x9ad1e0, 0xf36b90)
	/usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/xuperchain/xuper-sdk-go/xchain.(*Xchain).GenerateTxInput(0xc0002a6420, 0x0, 0xc000303b60, 0x0, 0x1, 0x40db86, 0x12, 0x0, 0xc0002ca310)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/xchain/xchain.go:208 +0x37
github.com/xuperchain/xuper-sdk-go/xchain.(*Xchain).GenComplianceCheckTx(0xc0002a6420, 0xc0000a2870, 0x20, 0xc0002aee00, 0x3a)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/xchain/xchain.go:99 +0xa1
github.com/xuperchain/xuper-sdk-go/xchain.(*Xchain).GenCompleteTxAndPost(0xc0002a6420, 0xc0000a2870, 0xa81602, 0x1, 0x2, 0xc0002aee00)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/xchain/xchain.go:407 +0x4d
github.com/xuperchain/xuper-sdk-go/contract.(*WasmContract).PostWasmContract(0xc0002a6410, 0xc0000a2870, 0xa821d8, 0x25, 0xa6a20d, 0x1)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/contract/contract.go:100 +0x141
github.com/xuperchain/xuper-sdk-go/contract.(*WasmContract).DeployWasmContract(0xc0002a6410, 0xc0000e3e20, 0xa821d8, 0x25, 0xa6a20d, 0x1, 0x8, 0xa78ad3, 0x18, 0xc0002a6410)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/contract/contract.go:52 +0x126
github.com/xuperchain/xuper-sdk-go/contract.TestJason(0xc0000f2300)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/contract/contract_test.go:216 +0x2fb
testing.tRunner(0xc0000f2300, 0xa9c368)
	/usr/local/go/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:960 +0x350

go sdk 使用国密生成的账号,在进行 EVM 与 Xchain 地址互转时结果不一致

add, _, _ := account.XchainToEVMAddress("qzuppnp2ZESdFf5Nd5AnDTWtBCASgg3cG")
fmt.Println(add)
fmt.Println("qzuppnp2ZESdFf5Nd5AnDTWtBCASgg3cG")

// outpt
1979D7D9326E313BFC3440523D68A417196B50BD
qzuppnp2ZESdFf5Nd5AnDTWtBCASgg3cG
add, _, _ := account.EVMToXchainAddress("1979D7D9326E313BFC3440523D68A417196B50BD")
fmt.Println(add)
fmt.Println("qzuppnp2ZESdFf5Nd5AnDTWtBCASgg3cG")

// outpt
SfJqiVXKNmZopWzMCjrJ6BjFfwDgZAApV
qzuppnp2ZESdFf5Nd5AnDTWtBCASgg3cG

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.