trustwallet / wallet-core

Cross-platform, cross-blockchain wallet library.
https://developer.trustwallet.com/wallet-core
Apache License 2.0
2.86k stars 1.6k forks source link

TRON TAPOS_ERROR #1532

Closed onesand closed 3 years ago

onesand commented 3 years ago

Describe the bug {"code":"TAPOS_ERROR","txid":"5fecec5a6ae1f958859a07d83bdaafb202bebcf9e4cd7d39d3c88f5cfb03f587","message":"5461706f7320636865636b206572726f72"}

To Reproduce Steps to reproduce the behavior:

Tron.TransferContract transferContract = Tron.TransferContract.newBuilder()
                        .setOwnerAddress(account.address())
                        .setToAddress("TWiPRXR5wXSEP54xqaRyWaG2mX2P1uKwZi")
                        .setAmount(10)
                        .build();

                JSONObject object = new JSONObject();
                object.put("num",1);
                OkGo.<String>post(TronNet.getBlockByLatestNum)
                        .tag(this)
                        .headers("Accept","application/json'")
                        .upRequestBody(RequestBody.create(object.toString(),MediaType.get("application/json; charset=utf-8")))
                        .execute(new StringCallback() {
                            @Override
                            public void onError(Response<String> response) {

                            }

                            @Override
                            public void onSuccess(Response<String> response) {
                                LogUtils.ln(response.body());
                                Gson gson = new Gson();

                                TronLasterBlockBean blockBean = gson.fromJson(response.body(),TronLasterBlockBean.class);

                                long time = blockBean.getBlock().get(0).getBlock_header().getRaw_data().getTimestamp();

                                Tron.BlockHeader blockHeader = Tron.BlockHeader.newBuilder()
                                        .setTimestamp(time)
                                        .setTxTrieRoot(ByteString.copyFrom(blockBean.getBlock().get(0).getBlock_header().getRaw_data().getTxTrieRoot().getBytes()))
                                        .setParentHash(ByteString.copyFrom(blockBean.getBlock().get(0).getBlock_header().getRaw_data().getParentHash().getBytes()))
                                        .setWitnessAddress(ByteString.copyFrom(blockBean.getBlock().get(0).getBlock_header().getRaw_data().getWitness_address().getBytes()))
                                        .setNumber(blockBean.getBlock().get(0).getBlock_header().getRaw_data().getNumber())
                                        .setVersion(blockBean.getBlock().get(0).getBlock_header().getRaw_data().getVersion())
                                        .build();

                                Tron.Transaction transaction  = Tron.Transaction.newBuilder()
                                        .setTimestamp(time)
                                        .setTransfer(transferContract)
                                        .setExpiration(time + (5 * 24 * 60 * 60 * 1000))
                                        .setBlockHeader(blockHeader)
                                        .build();

                                Tron.SigningInput signingInput = Tron.SigningInput.newBuilder()
                                        .setTransaction(transaction)
                                        .setPrivateKey(ByteString.copyFrom(privateKey)).build();

                                Tron.SigningOutput output = null;

                                try {
                                    output = AnySigner.sign(signingInput, CoinType.TRON, Tron.SigningOutput.parser());
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                                LogUtils.ln(output.getJson());

                                OkGo.<String>post(TronNet.broadCastTransaction)
                                        .tag(this)
                                        .upRequestBody(RequestBody.create(output.getJson(),MediaType.get("application/json; charset=utf-8")))
                                        .headers("Accept","application/json'")
                                        .headers("Content-Type","application/json'")
                                        .params("visible",true)
                                        .execute(new StringCallback() {
                                            @Override
                                            public void onError(Response<String> response) {

                                            }

                                            @Override
                                            public void onSuccess(Response<String> response) {
                                                LogUtils.ln(response.body());
                                            }
                                        });
                            }
                        });

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

onesand commented 3 years ago

Does anyone know? Please help.

hewigovens commented 3 years ago

A few things could go wrong:

  1. Does owner account have enough TRX?
  2. Amount should be represented with minimum unit, so 10 TRX is 10_000_000
  3. Try smaller expiration time
  4. other code looks correct to me, try to ask Tron team instead, possible issue: https://github.com/tronprotocol/java-tron/issues/857
onesand commented 3 years ago

1、TRX has 1900. 2、amount set 1_000_000 3、smaller expiration time set 10 60 1000

in nile network block head info :

{"blockID":"0000000001121a0394c06f7c3822517c8188b08e8fa39ad814db07d0c2b4aa5b","block_header":{"raw_data":{"number":17963523,"txTrieRoot":"0000000000000000000000000000000000000000000000000000000000000000","witness_address":"41b2f713d57dbcec679d93a8849fa0cd0e4db594ba","parentHash":"0000000001121a0227cf8c6719e5fdb972822df7e42c3051ec00d0ea3d76fc4c","version":21,"timestamp":1627004904000},"witness_signature":"a063c19b64056dd067c9d260dc8444c0fdc347a4b664a55e188d65ba47a4a8e90ee68c502f978a0475562db856505d9f07727cfc35e431f83bce520855df12c501"}}`

use above code then get:

{"raw_data":{"contract":[{"parameter":{"type_url":"type.googleapis.com/protocol.TransferContract","value":{"amount":1000000,"owner_address":"41a0fd3834ad94617d1a3db5ecb60af17990a2cfb6","to_address":"41e38d1a0b9455bb114f053bc45f363c42a2246bf9"}},"type":"TransferContract"}],"expiration":1627005504000,"ref_block_bytes":"1a03","ref_block_hash":"fa71bd3da90cbfb3","timestamp":1627004906921},"signature":["34cb72f13ecda445d8d0cf3bd91f95c603eae3ed2c2eafa570a8d8177158082260c7beb3406ac4897d62ee0f652c9b4f7f45d38f5dff5cf097fff4cb0e6af0db01"],"txID":"276bd4910d12bbd0781280e26ed81e1a06f03514a436c21381423b48e2fe4f4a"}

I think ref_block_hash is wrong.should be 94c06f7c3822517c but is fa71bd3da90cbfb3

hewigovens commented 3 years ago

Could you please try to send TRX on mainnet? not sure if testnet changes proto or not, we haven't touched https://github.com/trustwallet/wallet-core/blob/master/src/Tron/Protobuf/TronInternal.proto for years

onesand commented 3 years ago

On mainnet is also the same error.

hewigovens commented 3 years ago

hmm, it works on Trust tho, could you check your data again? e.g.: txTrieRoot looks suspicious 0000000000000000000000000000000000000000000000000000000000000000

onesand commented 3 years ago

mainnet:

getNowBlock return:

{"blockID":"0000000001eafdfe1dc30cd9fb76c81209232866e639b5e05b1072ae92cf5fc8","block_header":{"raw_data":{"number":32177662,"txTrieRoot":"84ee52b6c54997e05821939b32ae66a2296f4e7ddbb38db52916ff6bbec11efe","witness_address":"418a445facc2aa94d72292ebbcb2a611e9fd8a6c6e","parentHash":"0000000001eafdfd3cafe4726b9daf16c34bd77a4cfe5e6409661cff197b9961","version":21,"timestamp":1627008414000},"witness_signature":"48887d6496adfe5e35c135ba3480f4d0571be76fd2ccf6b12436cd0c2914078162c256a1c90eaf0e591a749e8816a845b17644eda6c7890e39845eb9292086cc01"}}

sign json:

{"raw_data":{"contract":[{"parameter":{"type_url":"type.googleapis.com/protocol.TransferContract","value":{"amount":1000000,"owner_address":"41a0fd3834ad94617d1a3db5ecb60af17990a2cfb6","to_address":"41e38d1a0b9455bb114f053bc45f363c42a2246bf9"}},"type":"TransferContract"}],"expiration":1627009014000,"ref_block_bytes":"fdfe","ref_block_hash":"895ffdda241e26a7","timestamp":1627008421143},"signature":["3e3a81afde4843cf662264b94181716cb04878c19cbee4f35ee73dd5ed7bb4e518fa1db2745253444e10115a51f742f1ba1ea34c283fe3e0db5008ae3408705b01"],"txID":"bffe38f9af9e840381273a7bf65e6a588f7061b6b24c42b35daa470c0ed93e42"}

Also Tapos check error.

Could you please provide a java code?This problem has bothered me for three days, and I really don’t know how to solve it.

onesand commented 3 years ago

After I solved the above problem, I found another error. I made sure that the private key and owner address I gave were correct.

validate signature error e9afc909e652ed1f0f6c63ccea59f16c4ba62cb73ca2fe1bc3d41230573fdb9033ce7480fb41fd85cb3763d335859d49edc4407f117f3d9c146898872eed6b9601 is signed by TWSFkDeQ9xs8XZCxLL3UWZkV9PJMANdpbb but it is not contained of permission.

onesand commented 3 years ago

Hi, I solved this problem.

BlockHeader:

.setTxTrieRoot(ByteString.copyFrom(blockBean.getBlock_header().getRaw_data().getTxTrieRoot().getBytes())) .setParentHash(ByteString.copyFrom(blockBean.getBlock_header().getRaw_data().getParentHash().getBytes())) .setWitnessAddress(ByteString.copyFrom(blockBean.getBlock_header().getRaw_data().getWitness_address().getBytes()))

to ⏬

.setTxTrieRoot(ByteString.copyFrom(Hex.decode(blockBean.getBlock_header().getRaw_data().getTxTrieRoot()))) .setParentHash(ByteString.copyFrom(Hex.decode(blockBean.getBlock_header().getRaw_data().getParentHash()))) .setWitnessAddress(ByteString.copyFrom(Hex.decode(blockBean.getBlock_header().getRaw_data().getWitness_address())))

hewigovens commented 3 years ago

👍

chamid commented 1 year ago

@onesand Can I know how you get the latest block info???