|
24 | 24 | import com.company.keystore.crypto.SHA3Utility; |
25 | 25 | import com.company.keystore.crypto.ed25519.Ed25519PrivateKey; |
26 | 26 | import com.company.keystore.crypto.ed25519.Ed25519PublicKey; |
27 | | -import com.company.keystore.util.Base58Utility; |
28 | 27 | import com.company.keystore.util.ByteUtil; |
29 | 28 | import com.company.protobuf.HatchModel; |
30 | 29 | import com.company.protobuf.ProtocolModel; |
@@ -1267,6 +1266,101 @@ public static JSONObject CreateSignToDeployforRuleTransfer(String fromPubkeyStr, |
1267 | 1266 | } |
1268 | 1267 | } |
1269 | 1268 |
|
| 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 | + |
1270 | 1364 | /** |
1271 | 1365 | * 多重签名的部署(发布者签名) |
1272 | 1366 | * @param fromPubkeyStr |
|
0 commit comments