|
36 | 36 | import org.tron.api.GrpcAPI.TransactionExtention;
|
37 | 37 | import org.tron.api.GrpcAPI.TransactionSignWeight;
|
38 | 38 | import org.tron.api.WalletGrpc;
|
| 39 | +import org.tron.api.WalletGrpc.WalletBlockingStub; |
39 | 40 | import org.tron.api.WalletSolidityGrpc;
|
40 | 41 | import org.tron.common.crypto.ECKey;
|
41 | 42 | import org.tron.common.crypto.ECKey.ECDSASignature;
|
|
74 | 75 | import org.tron.protos.contract.ExchangeContract.ExchangeInjectContract;
|
75 | 76 | import org.tron.protos.contract.ExchangeContract.ExchangeTransactionContract;
|
76 | 77 | import org.tron.protos.contract.ExchangeContract.ExchangeWithdrawContract;
|
| 78 | +import org.tron.protos.contract.MarketContract; |
77 | 79 | import org.tron.protos.contract.ProposalContract.ProposalApproveContract;
|
78 | 80 | import org.tron.protos.contract.ProposalContract.ProposalCreateContract;
|
79 | 81 | import org.tron.protos.contract.ProposalContract.ProposalDeleteContract;
|
@@ -5239,4 +5241,95 @@ public static boolean updateBrokerage(byte[] owner, int brokerage, String priKey
|
5239 | 5241 |
|
5240 | 5242 | return broadcastTransaction(transaction, blockingStubFull);
|
5241 | 5243 | }
|
| 5244 | + |
| 5245 | + /** |
| 5246 | + * constructor. |
| 5247 | + */ |
| 5248 | + public static boolean marketSellAsset(byte[] owner, byte[] sellTokenId, |
| 5249 | + long sellTokenQuantity, byte[] buyTokenId, long buyTokenQuantity, |
| 5250 | + int permissionId, String[] priKeys, WalletBlockingStub blockingStubFull) { |
| 5251 | + |
| 5252 | + MarketContract.MarketSellAssetContract.Builder builder = MarketContract.MarketSellAssetContract |
| 5253 | + .newBuilder(); |
| 5254 | + builder |
| 5255 | + .setOwnerAddress(ByteString.copyFrom(owner)) |
| 5256 | + .setSellTokenId(ByteString.copyFrom(sellTokenId)) |
| 5257 | + .setSellTokenQuantity(sellTokenQuantity) |
| 5258 | + .setBuyTokenId(ByteString.copyFrom(buyTokenId)) |
| 5259 | + .setBuyTokenQuantity(buyTokenQuantity); |
| 5260 | + |
| 5261 | + TransactionExtention transactionExtention = blockingStubFull.marketSellAsset(builder.build()); |
| 5262 | + if (transactionExtention == null) { |
| 5263 | + return false; |
| 5264 | + } |
| 5265 | + Return ret = transactionExtention.getResult(); |
| 5266 | + if (!ret.getResult()) { |
| 5267 | + System.out.println("Code = " + ret.getCode()); |
| 5268 | + System.out.println("Message = " + ret.getMessage().toStringUtf8()); |
| 5269 | + return false; |
| 5270 | + } |
| 5271 | + Transaction transaction = transactionExtention.getTransaction(); |
| 5272 | + if (transaction == null || transaction.getRawData().getContractCount() == 0) { |
| 5273 | + System.out.println("Transaction is empty"); |
| 5274 | + return false; |
| 5275 | + } |
| 5276 | + |
| 5277 | + if (transaction.getRawData().getContract(0).getType() |
| 5278 | + != ContractType.MarketSellAssetContract) { |
| 5279 | + return false; |
| 5280 | + } |
| 5281 | + |
| 5282 | + try { |
| 5283 | + transaction = setPermissionId(transaction, permissionId); |
| 5284 | + transaction = signTransaction(transaction, blockingStubFull, priKeys); |
| 5285 | + } catch (CancelException e) { |
| 5286 | + e.printStackTrace(); |
| 5287 | + } |
| 5288 | + return broadcastTransaction(transaction, blockingStubFull); |
| 5289 | + |
| 5290 | + } |
| 5291 | + |
| 5292 | + /** |
| 5293 | + * constructor. |
| 5294 | + */ |
| 5295 | + public static boolean marketCancelOrder(byte[] owner, byte[] orderId, |
| 5296 | + int permissionId, String[] priKeys, |
| 5297 | + WalletBlockingStub blockingStubFull) { |
| 5298 | + |
| 5299 | + MarketContract.MarketCancelOrderContract.Builder builder = MarketContract |
| 5300 | + .MarketCancelOrderContract.newBuilder(); |
| 5301 | + builder.setOwnerAddress(ByteString.copyFrom(owner)).setOrderId(ByteString.copyFrom(orderId)); |
| 5302 | + |
| 5303 | + TransactionExtention transactionExtention = blockingStubFull.marketCancelOrder(builder.build()); |
| 5304 | + |
| 5305 | + if (transactionExtention == null) { |
| 5306 | + return false; |
| 5307 | + } |
| 5308 | + Return ret = transactionExtention.getResult(); |
| 5309 | + if (!ret.getResult()) { |
| 5310 | + System.out.println("Code = " + ret.getCode()); |
| 5311 | + System.out.println("Message = " + ret.getMessage().toStringUtf8()); |
| 5312 | + return false; |
| 5313 | + } |
| 5314 | + Transaction transaction = transactionExtention.getTransaction(); |
| 5315 | + if (transaction == null || transaction.getRawData().getContractCount() == 0) { |
| 5316 | + System.out.println("Transaction is empty"); |
| 5317 | + return false; |
| 5318 | + } |
| 5319 | + |
| 5320 | + if (transaction.getRawData().getContract(0).getType() |
| 5321 | + != ContractType.MarketCancelOrderContract) { |
| 5322 | + System.out.println("Wrong ContractType :" |
| 5323 | + + transaction.getRawData().getContract(0).getType()); |
| 5324 | + return false; |
| 5325 | + } |
| 5326 | + |
| 5327 | + try { |
| 5328 | + transaction = setPermissionId(transaction, permissionId); |
| 5329 | + transaction = signTransaction(transaction,blockingStubFull,priKeys); |
| 5330 | + } catch (CancelException e) { |
| 5331 | + e.printStackTrace(); |
| 5332 | + } |
| 5333 | + return broadcastTransaction(transaction, blockingStubFull); |
| 5334 | + } |
5242 | 5335 | }
|
0 commit comments