Giter VIP home page Giter VIP logo

cita-sdk-java's People

Contributors

ashchan avatar baojuncz avatar boundless-forest avatar clowdrgn avatar conor10 avatar craigwilliams84 avatar dmi3coder avatar duanyytop avatar eepstein avatar ermyas avatar eztierney avatar fooock avatar iikirilov avatar jaycarey avatar joanesespanol avatar keith-cy avatar ligi avatar mine77 avatar nicksavers avatar qingyangkong avatar qingyanl avatar rainchen avatar the-wastl avatar thedoctor avatar timmyz avatar tramonex-nate avatar udld avatar vgorin avatar yangzhenlong avatar zengbing15 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cita-sdk-java's Issues

contractAddress mustn't has 0x prefix?

Transaction tx = Transaction.createFunctionCallTransaction(
                contractAddress,
                nonce,
                this.quota,
                this.validUntilBlock,
                VERSION,
                CHAINID,
                value,
                functionCallData);
        String rawTx = tx.sign(privateKey, isEd25519AndBlake2b,false);

When the contractAddress has 0x prefix, something wrong, the tx can't send to the contractAddress.
After remove 0x in contractAddress, it's ok.

getNonce can't work

In org/web3j/tx/CitaTransactionManager.java
getNonce should use LATEST rather than DefaultBlockParameterName.PENDING.
Because there are no PENDING in CITA.

getChainId should return BigInteger

org/nervos/appchain/protocol/core/methods/response/AppMetaData.java

    public void setChainId(int chainId) {
        this.chainId = chainId;
    }

    public int getChainId() {
        if (this.version == 0) {
            return this.chainId;
        } else if (this.version == 1) {
            return Integer.parseInt(this.chainIdV1);
        } else {
            throw new IllegalArgumentException("version number can only be 1 or 2");
        }
    }

old chainId is u32
new chainIdV1 is u256
So I think getChainId should return BigInteger
or String?
Same to argument of setChainId

Transaction 中 value 非零时 decodeContent() 失败

  • 在获取发送信息的时候 decodeContent 抛异常
sdk.appGetTransactionByHash("0xabc...").send().getTransaction().decodeContent();
  • 看了下代码, 在 com.cryptape.cita.utils.TransactionUtil#decodeContent
    public static Transaction
            decodeContent(String content) throws InvalidProtocolBufferException {

        Blockchain.UnverifiedTransaction unverifiedTx
                = Blockchain.UnverifiedTransaction.parseFrom(
                ConvertStrByte.hexStringToBytes(Numeric.cleanHexPrefix(content)));

        Blockchain.Transaction blockChainTx = unverifiedTx.getTransaction();

        int version = blockChainTx.getVersion();
        String nonce = blockChainTx.getNonce();
        long quota = blockChainTx.getQuota();
        long validUntilBlock = blockChainTx.getValidUntilBlock();
        String data = bytesToHexString(blockChainTx.getData());
        String value = bytesToHexString(blockChainTx.getValue());

        ......

由于 value 不为零, String value = bytesToHexString(blockChainTx.getValue()); 返回的 value 不是 0x 开头的, 后面转换的时候当 10 进制转换报错了

[doc mistake] nervosj/docs/zh-CN/Latest/Transaction.md

The statement txToCallContract in Line 2 does not match the references txToDeployContract.sign Line 3 :

1. //construct transaction
2. Transaction txToCallContract = Transction.createFunctionCallTransaction(to, nonce, quota, valid_until_block, version, chainId, value, init);
3. String signedTx = txToDeployContract.sign(this.config.getPrivateKey(), false, false);
4. AppSendTransaction appSendTx = service.sendRawTransaction(signedTx);

Bytes类使用不了DynamicBytes使用也有问题

Bytes类的构造函数是protected,引入后不能new,且bytes长度需要在0到32,请问下这里是为什么?
DynamicBytes的使用也有问题,在TypedAbi.java中的ctor.newInstance(value);会失败,请问该怎么解决?
屏幕截图 2022-11-20 223449

gradle shadowJar got exception

Welcome to Gradle 5.4.1!

Here are the highlights of this release:

  • Run builds with JDK12
  • New API for Incremental Tasks
  • Updates to native projects, including Swift 5 support

For more details see https://docs.gradle.org/5.4.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

  • Where:
    Build file '/cita-sdk-java/console/build.gradle' line: 12

  • What went wrong:
    A problem occurred evaluating project ':console'.

Could not get unknown property 'classesDir' for test classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 27s

优化合约生成

  1. 生成合约时,nonce, validUntilBlock, version, chainId这几个参数都是重复要输入的,自动获取或者通过构造函数传入
  2. 非payable的函数生成方法应该不用传value
  3. 生成合约类时候对于 payable 函数多一个 weivalue,大家不理解,最好能在文档或社区中增加一篇详细说明
    来源用户反馈:https://talk.citahub.com/t/topic/777

为什么交易直接就能出块成功?

合约地址:6060604052341561000f57600080fd5b60408051908101604052600b81527f68656c6c6f20776f726c640000000000000000000000000000000000000000006020820152600090805161005692916020019061005c565b506100f7565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009d57805160ff19168380011785556100ca565b828001600101855582156100ca579182015b828111156100ca5782518255916020019190600101906100af565b506100d69291506100da565b5090565b6100f491905b808211156100d657600081556001016100e0565b90565b6102c3806101066000396000f30060606040526004361061004b5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166320965255811461005057806393a09352146100da575b600080fd5b341561005b57600080fd5b61006361012d565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561009f578082015183820152602001610087565b50505050905090810190601f1680156100cc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156100e557600080fd5b61012b60046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506101d695505050505050565b005b6101356101ed565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101cb5780601f106101a0576101008083540402835291602001916101cb565b820191906000526020600020905b8154815290600101906020018083116101ae57829003601f168201915b505050505090505b90565b60008180516101e99291602001906101ff565b5050565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061024057805160ff191683800117855561026d565b8280016001018555821561026d579182015b8281111561026d578251825591602001919060010190610252565b5061027992915061027d565b5090565b6101d391905b8082111561027957600081556001016102835600a165627a7a72305820086c5bf2a74080392d819fbd84ddb063f16da81bfcfa3e0d9d095fc2b99588220029

网络地址:http://121.196.200.225:1337

from:0x9866174664d0eec7988fcc223ee14f6398cd9448
to:0x5f78ee58f5900045d9149c051e12c3b401e8c4df
amount:1
txHash:0xda58810ab925c40d1eea2d60813e66fc5fccab0acda59973dc8e2b3e117fc75d

from地址是我随意生成的地址,肯定没有余额的,为什么这笔交易能直接成功?

调用合约查询函数返回的数据中包括非法数据

使用citaj 调用合约查询接口,
接口返回hex数据
通过java解析把数据解析成UTF-8普通字符串时,出现乱码

查询方法1结果:
0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008f62616e6b5472616e736665725061797c2b7c307c2b7c307c2b7c3130303030307c2b7c3130303030307c2b7c307c2b7c3130303030307c2b7c50592d32643062663662662d313937302d343330362d383161382d3361343334663463356534377c2b7c7c2b7c323031392d30382d32382031353a32313a30377c2b7c317c2b7ce8aea2e58d95e5b7b2e7a1aee8aea40000000000000000000000000000000000

字符串结果1:
�bankTransferPay|+|0|+|0|+|100000|+|100000|+|0|+|100000|+|PY-2d0bf6bf-1970-4306-81a8-3a434f4c5e47|+||+|2019-08-28 15:21:07|+|1|+|订单已确认

查询方法2结果:
0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000457c2b7c7c2b7c7c2b7c7c2b7c323031392d30382d32382031353a32353a35327c2b7c7c2b7c7c2b7c7c2b7c323031392d30382d32382031353a32353a30387c2b7c357c2b7c000000000000000000000000000000000000000000000000000000

字符串结果2:
E|+||+||+||+|2019-08-28 15:25:52|+||+||+||+|2019-08-28 15:25:08|+|5|+|

JAVA 代码:

//hex转字符串

//16进制转换成为string类型字符串
private static String hexStringToString(String s) {
    if (s == null || s.equals("")) {
        return null;
    }
    s = s.replace(" ", "");
    byte[] baKeyword = new byte[s.length() / 2];
    for (int i = 0; i < baKeyword.length; i++) {
        try {
            if (s.substring(i * 2, i * 2 + 2).equals("00")) {
                continue;
            }
            baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    try {
        s = new String(baKeyword, "UTF-8");
        new String();
    } catch (Exception e1) {
        e1.printStackTrace();
    }

    return s;
}

//把前导0的字符串转为正常字符串
private static String hexStringToStringOne(String hexStr) {
    String bigInt = new BigInteger(hexStr, 16).toString(16);
    return bigInt;
}


//链上取出的十六进制字符串转为普通字符串
private String hexToString(String hexStr) {
    String BigIntToString = hexStringToStringOne(hexStr.substring(2));
    String orderInfo = hexStringToString(BigIntToString).replace("\u0000", "").replace("\u0001", "").replace("\t", "");
    return orderInfo;
}


//调用合约查询方法获取结果
public String callContractFunc() {
    Call call = new Call('from', contractAddress, callData);
    //该结果有乱码(多余字符)
    String hexStr = citaJService.appCall(call, DefaultBlockParameterName.LATEST).send().getValue();
    return hexToString(hexStr);
}

另外,采用Cita JS sdk 调用合约查询接口,会直接返回正确的字符串数据

代码如下:

(async () => {
    var contractInstance = new citaSDK.base.Contract(abi, contractAddress);
    var queryRes = await contractInstance.methods['myQueryFunc'](params).call();

    //打印查询结果,该结果正确,不包含乱码(多余字符)
    console.log('query res', queryRes);
})();

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.