Skip to content
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

发送交易时报错 #2

Open
liuzhijun23 opened this issue Dec 7, 2018 · 10 comments
Open

发送交易时报错 #2

liuzhijun23 opened this issue Dec 7, 2018 · 10 comments

Comments

@liuzhijun23
Copy link

我在本地建立了一条私有链,用你的SDK的例子,查询余额操作正常,但是在发送交易的时候,报错:
我的程序是:
`public class TestEOS {
public static String url_wallet = "http://192.168.1.75:18888";
public static String url_chain = "http://192.168.1.75:8888";//"http://jungle.cryptolions.io:18888"
public static EosApi client;
public static void main(String[] args) throws Exception{
BasicConfigurator.configure();
client = EosApiFactory.create(url_wallet, url_chain, url_chain);
ChainInfo info = client.getChainInfo();
//System.out.println("chain info:"+info);

   // getBalance("acctoken","acca");

    transfer("acctoken","acca","accb","100.0000 SYS");
    TimeUnit.MINUTES.sleep(50000);
}

static void getBalance(String token,String account){
    List<String> ret = client.getCurrencyBalance(token,account,"SYS");
    System.out.println("account balance:"+ret);
}

static void transfer(String token,String from,String to,String money) throws Exception {
    ObjectMapper mapper = EosApiServiceGenerator.getMapper();

    // ① pack transfer data
    TransferArg transferArg = new TransferArg(from, to, money, "我是中国人");
    AbiJsonToBin data = client.abiJsonToBin(token, "transfer", transferArg);
    System.out.println("bin= " + data.getBinargs());

    // ② get the latest block info
    Block block = client.getBlock(client.getChainInfo().getHeadBlockId());
    System.out.println("blockNum=" + block.getBlockNum());

    // ③ create the authorization
    List<TransactionAuthorization> authorizations = Arrays.asList(new TransactionAuthorization(from, "active"));

    // ④ build the all actions
    List<TransactionAction> actions = Arrays.asList(//
            new TransactionAction(token, "transfer", authorizations, data.getBinargs())//
    );

    // ⑤ build the packed transaction
    PackedTransaction packedTransaction = new PackedTransaction();
    packedTransaction.setRefBlockPrefix(block.getRefBlockPrefix());
    packedTransaction.setRefBlockNum(block.getBlockNum());
    // expired after 3 minutes
    String expiration = ZonedDateTime.now(ZoneId.of("GMT")).plusMinutes(3).truncatedTo(ChronoUnit.SECONDS).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    packedTransaction.setExpiration(LocalDateTime.parse(expiration));
    packedTransaction.setRegion("0");
    packedTransaction.setMaxNetUsageWords(0);
    packedTransaction.setMaxCpuUsageMs(0);
    packedTransaction.setActions(actions);

    // ⑥ unlock the creator's wallet
    try {
        client.unlockWallet("default", "PW5JECR3XedNovw8w8cPmYBe52eH51buki4rVVHUwunWFeJNco4Vd");
    } catch (EosApiException ex) {
        System.err.println(ex.getMessage());
    }

    // ⑦ sign the transaction
    SignedPackedTransaction signedPackedTransaction = client.signTransaction(packedTransaction, //
            Arrays.asList("EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"), //
            "38dc6e87bb9f6b33a21dd56b9f2c24813d83c71009077279c8d746fbd0eaf09d");

    System.out.println("signedPackedTransaction=" + mapper.writeValueAsString(signedPackedTransaction));
    System.out.println("\n--------------------------------\n");

    // ⑧ push the signed transaction
    PushedTransaction pushedTransaction = client.pushTransaction("none", signedPackedTransaction);
    System.out.println("pushedTransaction=" + mapper.writeValueAsString(pushedTransaction));
}

}报的错误是:Exception in thread "main" io.jafka.jeos.exception.EosApiException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of io.jafka.jeos.core.common.transaction.TransactionAuthorization (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 242] (through reference chain: io.jafka.jeos.core.common.transaction.SignedPackedTransaction["actions"]->java.util.ArrayList[0]->io.jafka.jeos.core.common.transaction.TransactionAction["authorization"]->java.util.ArrayList[0])
at io.jafka.jeos.impl.EosApiServiceGenerator.executeSync(EosApiServiceGenerator.java:64)
at io.jafka.jeos.impl.EosApiRestClientImpl.signTransaction(EosApiRestClientImpl.java:210)
at org.web3j.sample.TestEOS.transfer(TestEOS.java:95)
at org.web3j.sample.TestEOS.main(TestEOS.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of io.jafka.jeos.core.common.transaction.TransactionAuthorization (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 242] (through reference chain: io.jafka.jeos.core.common.transaction.SignedPackedTransaction["actions"]->java.util.ArrayList[0]->io.jafka.jeos.core.common.transaction.TransactionAction["authorization"]->java.util.ArrayList[0])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1452)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1028)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1297)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:286)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:286)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1611)
at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1203)
at retrofit2.converter.jackson.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:32)16:23:48.399 [main] INFO io.jafka.jeos.impl.LoggingInterceptor - OkHttp-6-3--<head http://192.168.1.75:18888/v1/wallet/sign_transaction 9ms Connection: close`

我在本地执行json-rpc命令:
curl http://192.168.1.75:18888/v1/wallet/sign_transaction -d ' [ { "expiration" : "2018-12-07T06:46:48", "ref_block_num" : 56141, "ref_block_prefix" : 3654011199, "max_net_usage_words" : 0, "max_cpu_usage_ms" : 0, "context_free_actions" : [ ], "actions" : [ { "account" : "acctoken", "name" : "transfer", "authorization" : [ { "actor" : "acca", "permission" : "active" } ], "data" : "0000000000601032000000000070103240420f000000000004535953000000000fe68891e698afe4b8ade59bbde4baba" } ], "transaction_extensions" : [ ], "context_free_data" : [ ], "region" : "0" }, [ "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" ], "38dc6e87bb9f6b33a21dd56b9f2c24813d83c71009077279c8d746fbd0eaf09d" ] '
是由结果的:
{"expiration":"2018-12-07T06:46:48","ref_block_num":56141,"ref_block_prefix":3654011199,"max_net_usage_words":0,"max_cpu_usage_ms":0,"delay_sec":0,"context_free_actions":[],"actions":[{"account":"acctoken","name":"transfer","authorization":[{"actor":"acca","permission":"active"}],"data":"0000000000601032000000000070103240420f000000000004535953000000000fe68891e698afe4b8ade59bbde4baba"}],"transaction_extensions":[],"signatures":["SIG_K1_JyNeuGBhirhUC7nLcZTxPiUKxBmTTD3dRRDbyDEpMMuTq6qTawuaG1jsGs4hKQRBYTGJzQwWyyLdwwJ7U8CevJtMdX389A"],"context_free_data":[]}
求大神帮忙看一下是什么原因。

@adyliu
Copy link
Owner

adyliu commented Dec 7, 2018

看起来是无法反序列化,你将反序列化失败的文本输出来看看。

另外内容可以markdown格式化下

@liuzhijun23
Copy link
Author

我现在在仿真,在源码里面打断点调试

@adyliu
Copy link
Owner

adyliu commented Dec 7, 2018

已经修复了此问题,临时发布了SNAPSHOT版本
https://github.com/adyliu/jeos#latest-snapshot-version

0.9.14版本 http://repo1.maven.org/maven2/io/jafka/jeos/0.9.14/ 已经发布,预计未来几个小时会同步到全网。

@liuzhijun23
Copy link
Author

新版本有Gradle版本吗?

@adyliu
Copy link
Owner

adyliu commented Dec 7, 2018

可以了 已经同步了

compile group: 'io.jafka', name: 'jeos', version: '0.9.14'

@liuzhijun23
Copy link
Author

功能已经正常了,可以正常转账了,给大神点赞!

@liuzhijun23
Copy link
Author

请问大神一个问题,如果在android App上面调用这个库来转账,上面说的在线转账需要启动keosd服务所以不能用,这种情况需要用离线签名转账方式。这个函数:
localApi.transfer(arg, privateKey, from1, to1, quantity, memo);
它在哪里设置代币名称(比如eosio.token)?

@liuzhijun23
Copy link
Author

`@Override
public PushTransactionRequest transfer(SignArg arg, String privateKey, String from, String to, String quantity, String memo) {
// ① pack transfer data
TransferArg transferArg = new TransferArg(from, to, quantity, memo);
String transferData = Packer.packTransfer(transferArg);
//

    // ③ create the authorization
    List<TransactionAuthorization> authorizations = Arrays.asList(new TransactionAuthorization(from, "active"));

    // ④ build the all actions
    List<TransactionAction> actions = Arrays.asList(//
            new TransactionAction("eosio.token", "transfer", authorizations, transferData)//
    );

    // ⑤ build the packed transaction
    PackedTransaction packedTransaction = new PackedTransaction();
    packedTransaction.setExpiration(arg.getHeadBlockTime().plusSeconds(arg.getExpiredSecond()));
    packedTransaction.setRefBlockNum(arg.getLastIrreversibleBlockNum());
    packedTransaction.setRefBlockPrefix(arg.getRefBlockPrefix());
    
    packedTransaction.setMaxNetUsageWords(0);
    packedTransaction.setMaxCpuUsageMs(0);
    packedTransaction.setDelaySec(0);
    packedTransaction.setActions(actions);

    String hash = sign(privateKey, arg, packedTransaction);
    PushTransactionRequest req = new PushTransactionRequest();
    req.setTransaction(packedTransaction);
    req.setSignatures(Arrays.asList(hash));
    return req;
}`

这里已经把代币名称(eosio.token)写死在函数源码里,需要设置成参数让用户去设置。

@lecletest
Copy link

@liuzhijun23 Hi
I want to know where is sign method (String hash = sign(privateKey, arg, packedTransaction); ) is located?

Thanks you so much!

@lecletest
Copy link

I have a smart contract with the method name is crepoll how can I call it from java and write the record to blockchain? @liuzhijun23 @adyliu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants