Skip to content

Commit 22f61bf

Browse files
author
liuchen
committed
support hex addr for pay destination
1 parent 0687ed2 commit 22f61bf

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

chainsql/src/main/java/com/peersafe/chainsql/core/Ripple.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.peersafe.base.core.types.known.tx.Transaction;
1616
import com.peersafe.chainsql.util.Util;
1717

18+
import static com.peersafe.base.config.Config.getB58IdentiferCodecs;
19+
1820
/**
1921
* @author mail_
2022
*
@@ -81,6 +83,13 @@ protected JSONObject prepareSigned() {
8183
private Ripple pay(String accountId,Amount amount){
8284
mTxJson = new JSONObject();
8385
mTxJson.put("Account", this.connection.address);
86+
87+
String addrPrefix = accountId.substring(0,2);
88+
if(addrPrefix.equals("0x"))
89+
{
90+
byte[] addrByte = Util.hexToBytes(accountId.substring(2));
91+
accountId = getB58IdentiferCodecs().encodeAddress(addrByte);
92+
}
8493
if(amount.currency() != Currency.ZXC)
8594
{
8695
JSONObject result = this.connection.client.accountInfo(amount.issuer());

chainsql/src/main/java/com/peersafe/chainsql/util/Util.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.peersafe.base.utils.Utils;
2727
import com.peersafe.chainsql.crypto.EncryptCommon;
2828
import com.peersafe.chainsql.net.Connection;
29+
import com.peersafe.base.encodings.common.B16;
2930

3031

3132
public class Util {
@@ -115,11 +116,12 @@ public static String bytesToHex(byte[] bytes) {
115116
* @return Hexed byte array.
116117
*/
117118
public static byte[] hexToBytes(String bytes){
118-
ByteArrayOutputStream baos=new ByteArrayOutputStream(bytes.length()/2);
119-
//将每2位16进制整数组装成一个字节
120-
for(int i=0;i<bytes.length();i+=2)
121-
baos.write((hexString.indexOf(bytes.charAt(i))<<4 |hexString.indexOf(bytes.charAt(i+1))));
122-
return baos.toByteArray();
119+
return B16.decode(bytes);
120+
// ByteArrayOutputStream baos=new ByteArrayOutputStream(bytes.length()/2);
121+
// //将每2位16进制整数组装成一个字节
122+
// for(int i=0;i<bytes.length();i+=2)
123+
// baos.write((hexString.indexOf(bytes.charAt(i))<<4 |hexString.indexOf(bytes.charAt(i+1))));
124+
// return baos.toByteArray();
123125
}
124126

125127
/**

0 commit comments

Comments
 (0)