Skip to content

Commit f21f33b

Browse files
update TxUtility
1 parent dee4c42 commit f21f33b

2 files changed

Lines changed: 119 additions & 6 deletions

File tree

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,26 @@ APPSDK是提供给APP调用的方法,主要是提供给实现普通转账事
504504
TxUtility. CreateSignToDeployforRuleTransfer()
505505
参数:
506506
1)、发送者公钥(十六进制字符串)
507-
2)、事务哈希(十六进制字符串)
507+
2)、事务哈希(十六进制字符串,资产部署时的事务哈希)
508+
3)、私钥(十六进制字符串)
509+
4)、nonce(Long)
510+
5)、from(十六进制字符串,公钥)
511+
6)、to(十六进制字符串,目标地址的公钥哈希)
512+
7)、value(BigDecimal,转发金额,必须大于0,整数)
513+
返回类型:Json
514+
返回值:
515+
{
516+
data : Transaction;
517+
(int)statusCode:0
518+
(String)message:null
519+
}
520+
```
521+
1.32构造签名的资产定义的转账的规则调用事务(传部署的160哈希)
522+
```
523+
TxUtility.CreateSignToDeployforRuleTransferAsHash160()
524+
参数:
525+
1)、发送者公钥(十六进制字符串)
526+
2)、160哈希(十六进制字符串,资产部署时的160哈希值)
508527
3)、私钥(十六进制字符串)
509528
4)、nonce(Long)
510529
5)、from(十六进制字符串,公钥)
@@ -518,7 +537,7 @@ APPSDK是提供给APP调用的方法,主要是提供给实现普通转账事
518537
(String)message:null
519538
}
520539
```
521-
1.32 获取Asset资产部署的详细信息
540+
1.33 获取Asset资产部署的详细信息
522541
```
523542
* 方法:TxUtility.getAsset()
524543
* 参数:payload(十六进制字符串)
@@ -530,7 +549,7 @@ APPSDK是提供给APP调用的方法,主要是提供给实现普通转账事
530549
(String)message::对象的所有参数
531550
}
532551
```
533-
1.33 获取AssetChangeowner资产更换所有者的详细信息
552+
1.34 获取AssetChangeowner资产更换所有者的详细信息
534553
```
535554
* 方法:TxUtility.getAssetChangeowner()
536555
* 参数:payload(十六进制字符串)
@@ -542,7 +561,7 @@ APPSDK是提供给APP调用的方法,主要是提供给实现普通转账事
542561
(String)message::对象的所有参数
543562
}
544563
```
545-
1.34 获取AssetIncreased资产增发的详细信息
564+
1.35 获取AssetIncreased资产增发的详细信息
546565
```
547566
* 方法:TxUtility.getAssetIncreased()
548567
* 参数:payload(十六进制字符串)
@@ -554,7 +573,7 @@ APPSDK是提供给APP调用的方法,主要是提供给实现普通转账事
554573
(String)message::对象的所有参数
555574
}
556575
```
557-
1.35 获取AssetTransfer资产转账的详细信息
576+
1.36 获取AssetTransfer资产转账的详细信息
558577
```
559578
* 方法:TxUtility.getAssetTransfer()
560579
* 参数:payload(十六进制字符串)

src/main/java/com/company/keystore/wallet/TxUtility.java

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.company.keystore.crypto.SHA3Utility;
2525
import com.company.keystore.crypto.ed25519.Ed25519PrivateKey;
2626
import com.company.keystore.crypto.ed25519.Ed25519PublicKey;
27-
import com.company.keystore.util.Base58Utility;
2827
import com.company.keystore.util.ByteUtil;
2928
import com.company.protobuf.HatchModel;
3029
import com.company.protobuf.ProtocolModel;
@@ -1267,6 +1266,101 @@ public static JSONObject CreateSignToDeployforRuleTransfer(String fromPubkeyStr,
12671266
}
12681267
}
12691268

1269+
/**
1270+
* 构造资产定义的转账事务(160哈希)
1271+
* @param fromPubkeyStr
1272+
* @param hash160
1273+
* @param nonce
1274+
* @param from
1275+
* @param to
1276+
* @param value
1277+
* @return
1278+
*/
1279+
public static JSONObject CreateDeployforRuleAssetTransferAsHash160(String fromPubkeyStr, String hash160, Long nonce, byte[] from, byte[] to, BigDecimal value) {
1280+
try {
1281+
value = value.multiply(BigDecimal.valueOf(rate));
1282+
AssetTransfer assetTransfer = new AssetTransfer(from, to, value.longValue());
1283+
//版本号
1284+
byte[] version = new byte[1];
1285+
version[0] = 0x01;
1286+
//类型
1287+
byte[] type = new byte[1];
1288+
type[0] = 0x08;
1289+
//Nonce 无符号64位
1290+
byte[] nonece = BigEndian.encodeUint64(nonce + 1);
1291+
//签发者公钥哈希 20字节
1292+
byte[] fromPubkeyHash = Hex.decodeHex(fromPubkeyStr.toCharArray());
1293+
//gas单价
1294+
byte[] gasPrice = ByteUtil.longToBytes(obtainServiceCharge(100000L, serviceCharge));
1295+
//分享收益 无符号64位
1296+
BigDecimal bdAmount = BigDecimal.valueOf(0);
1297+
byte[] Amount = ByteUtil.longToBytes(bdAmount.longValue());
1298+
//为签名留白
1299+
byte[] signull = new byte[64];
1300+
//接收者公钥哈希
1301+
byte[] toPubkeyHash = Hex.decodeHex(hash160.toCharArray());
1302+
//构造payload
1303+
byte[] payload = assetTransfer.RLPdeserialization();
1304+
//长度
1305+
byte[] payLoadLength = BigEndian.encodeUint32(payload.length + 1);
1306+
byte[] allPayload = ByteUtil.merge(payLoadLength, new byte[]{0x01}, payload);
1307+
byte[] RawTransaction = ByteUtil.merge(version, type, nonece, fromPubkeyHash, gasPrice, Amount, signull, toPubkeyHash, allPayload);
1308+
String RawTransactionStr = new String(Hex.encodeHex(RawTransaction));
1309+
JSONObject jsonObject = new JSONObject();
1310+
jsonObject.put("RawTransactionHex",RawTransactionStr);
1311+
jsonObject.put("code",2000);
1312+
return jsonObject;
1313+
} catch (Exception e) {
1314+
APIResult apiResult = new APIResult();
1315+
apiResult.setMessage("exception error");
1316+
apiResult.setStatusCode(5000);
1317+
String jsonString = JSON.toJSONString(apiResult);
1318+
JSONObject json = JSON.parseObject(jsonString);
1319+
return json;
1320+
}
1321+
}
1322+
1323+
/**
1324+
* 构造签名的资产定义的转账事务(160哈希)
1325+
* @param fromPubkeyStr
1326+
* @param hash160
1327+
* @param prikeyStr
1328+
* @param nonce
1329+
* @param from
1330+
* @param to
1331+
* @param value
1332+
* @return
1333+
*/
1334+
public static JSONObject CreateSignToDeployforRuleTransferAsHash160(String fromPubkeyStr, String hash160, String prikeyStr, Long nonce, String from, String to, BigDecimal value) {
1335+
try {
1336+
byte[] fromBy = Hex.decodeHex(from.toCharArray());
1337+
byte[] toBy = Hex.decodeHex(to.toCharArray());
1338+
JSONObject jsonObject = CreateDeployforRuleAssetTransferAsHash160(fromPubkeyStr, hash160, nonce, fromBy, toBy, value);
1339+
if(jsonObject.getInteger("code") == 5000){
1340+
return jsonObject;
1341+
}
1342+
String RawTransactionHex = jsonObject.getString("RawTransactionHex");
1343+
byte[] signRawBasicTransaction = Hex.decodeHex(signRawBasicTransaction(RawTransactionHex, prikeyStr).toCharArray());
1344+
byte[] hash = ByteUtil.bytearraycopy(signRawBasicTransaction, 1, 32);
1345+
String txHash = new String(Hex.encodeHex(hash));
1346+
String traninfo = new String(Hex.encodeHex(signRawBasicTransaction));
1347+
APIResult result = new APIResult();
1348+
result.setData(txHash);
1349+
result.setMessage(traninfo);
1350+
result.setStatusCode(2000);
1351+
String jsonString = JSON.toJSONString(result);
1352+
JSONObject json = JSON.parseObject(jsonString);
1353+
return json;
1354+
} catch (Exception e) {
1355+
APIResult apiResult = new APIResult();
1356+
apiResult.setMessage("事务构造有问题");
1357+
apiResult.setStatusCode(5000);
1358+
String jsonString = JSON.toJSONString(apiResult);
1359+
JSONObject json = JSON.parseObject(jsonString);
1360+
return json;
1361+
}
1362+
}
1363+
12701364
/**
12711365
* 多重签名的部署(发布者签名)
12721366
* @param fromPubkeyStr

0 commit comments

Comments
 (0)