tronprotocol / trident

150 stars 117 forks source link

Binance ID and TRON address automatic conversion #132

Open KevinShen1124 opened 5 months ago

KevinShen1124 commented 5 months ago

Using this method, entering the Binance ID when executing a transaction will automatically convert it into a TRON address.

org.tron.trident.abi.datatypes.Function transfer = new org.tron.trident.abi.datatypes.Function(
                        "transfer",
                        Arrays.asList(new Address(toAddress), new Uint256(BigInteger.valueOf(
                                (realAmount.multiply(BigDecimal.valueOf(10L).pow(trc20Contract.decimals().intValue())))
                                        .longValue())
                                .multiply(BigInteger.valueOf(10L).pow(0)))),
                        Arrays.asList(new org.tron.trident.abi.TypeReference<Bool>() {
                        }));
                TransactionBuilder builder = apiWrapper.triggerCall(
                        Base58Check.bytesToBase58(ApiWrapper.parseAddress(fromAddress).toByteArray()),
                        Base58Check.bytesToBase58(ApiWrapper.parseAddress(contract.getAddress()).toByteArray()),
                        transfer);

When I enter all other random numbers, the response is unknown address. Only the Binance ID will be automatically converted into a TRON address. It is recommended to adjust the package to include Binance ID in unknown addresses instead of automatically converting addresses. It was sent to an unknown address, can I get it back?

endiaoekoe commented 5 months ago

Using this method, entering the Binance ID when executing a transaction will automatically convert it into a TRON address.

org.tron.trident.abi.datatypes.Function transfer = new org.tron.trident.abi.datatypes.Function(
                      "transfer",
                      Arrays.asList(new Address(toAddress), new Uint256(BigInteger.valueOf(
                              (realAmount.multiply(BigDecimal.valueOf(10L).pow(trc20Contract.decimals().intValue())))
                                      .longValue())
                              .multiply(BigInteger.valueOf(10L).pow(0)))),
                      Arrays.asList(new org.tron.trident.abi.TypeReference<Bool>() {
                      }));
              TransactionBuilder builder = apiWrapper.triggerCall(
                      Base58Check.bytesToBase58(ApiWrapper.parseAddress(fromAddress).toByteArray()),
                      Base58Check.bytesToBase58(ApiWrapper.parseAddress(contract.getAddress()).toByteArray()),
                      transfer);

When I enter all other random numbers, the response is unknown address. Only the Binance ID will be automatically converted into a TRON address. It is recommended to adjust the package to include Binance ID in unknown addresses instead of automatically converting addresses. It was sent to an unknown address, can I get it back?

hi, @KevinShen1124 I think you may have two questions from your description above. 1.first one is when you entered a Binance ID(a number),trident SDK will convert it to a tron address,but when you entered a random number it will be convert to an unknown address. I just check the source code of the method 'new Address(toAddress)',you can see the code will go to the else part when you enter a number(binance id or other random number),also the convert mechanism is compatible with ETH address format.

public Address(String value) {
        if (value.startsWith("T")) {
            byte[] rawValue = Base58Check.base58ToBytes(value);
            this.value = new Uint(DEFAULT_LENGTH, Numeric.toBigInt(Arrays.copyOfRange(rawValue, 1, 21)));
        } else if (value.startsWith("41")) {
            this.value = new Uint(DEFAULT_LENGTH, Numeric.toBigInt(value.substring(2)));
        } else {
            // ETH compatible
            this.value = new Uint(DEFAULT_LENGTH, Numeric.toBigInt(value));
        }
    }
  1. If it was sent to an unknown address, can I get it back? as far as I know,if you transfer assets to an unknown address to which you don't have a private key of the address, you can't not get the asset back