Skip to content

Commit f40b729

Browse files
author
[a561842] Hubert Marteau
committed
Management of CreateRawTransactions
1 parent ad536c5 commit f40b729

File tree

10 files changed

+310
-123
lines changed

10 files changed

+310
-123
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>MultiChainJavaAPI</groupId>
55
<artifactId>MultiChainJavaAPI</artifactId>
6-
<version>0.4.10-SNAPSHOT</version>
6+
<version>0.4.11-SNAPSHOT</version>
77

88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/multichain/command/RAWTransactionCommand.java

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import multichain.command.builders.QueryBuilderRAWTransaction;
1313
import multichain.object.Address;
14-
import multichain.object.AddressBalanceAsset;
14+
import multichain.object.AddressBalance;
1515
import multichain.object.SignedTransactionRAW;
1616
import multichain.object.TransactionRAW;
1717
import multichain.object.formatters.RAWTransactionFormatter;
@@ -20,7 +20,7 @@
2020

2121
/**
2222
* @author Ub - H. MARTEAU
23-
* @version 3.0
23+
* @version 4.10
2424
*/
2525
public class RAWTransactionCommand extends QueryBuilderRAWTransaction {
2626

@@ -354,63 +354,76 @@ public String createRawSendFrom(String address, List<RawParam> rawParams) throws
354354
* Note that the transaction's inputs are not signed, and
355355
* it is not stored in the wallet or transmitted to the network.
356356
*
357+
* Create a transaction spending the given inputs.
358+
*
357359
* Arguments:
358-
* 1. "transactions" (string, required) A json array of json objects
359-
* [
360-
* {
361-
* "txid":"id", (string, required) The transaction id
362-
* "vout":n (numeric, required) The output number
363-
* }
364-
* ,...
365-
* ]
366-
* 2. "addresses" (string, required) a json object with addresses as keys and amounts as values
367-
* {
368-
* "address":
369-
* x.xxx (numeric, required) The key is the address, the value is the native currency amount
370-
* or
371-
* { (object) A json object of assets to send
372-
* "asset-identifier" : asset-quantity
373-
* ,...
374-
* }
375-
* or
376-
* { (object) A json object describing new asset issue
377-
* "issue" :
378-
* {
379-
* "raw" : n (numeric, required) The asset total amount in raw units
380-
* ,...
381-
* }
382-
* ,...
383-
* }
384-
* or
385-
* { (object) A json object describing follow-on asset issue
386-
* "issuemore" :
387-
* {
388-
* "asset" : "asset-identifier" (string, required) Asset identifier - one of the following: issue txid. asset
389-
* reference, asset name.
390-
* "raw" : n (numeric, required) The asset total amount in raw units
391-
* ,...
392-
* }
393-
* ,...
394-
* }
395-
* or
396-
* { (object) A json object describing permission change
397-
* "permissions" :
398-
* {
399-
* "type" : "permission(s)" (string,required) Permission strings, comma delimited. Possible values:
400-
* connect,send,receive,issue,mine,admin,activate
401-
* "startblock" (numeric, optional) Block to apply permissions from (inclusive). Default - 0
402-
* "endblock" (numeric, optional) Block to apply permissions to (exclusive). Default - 4294967295
403-
* "timestamp" (numeric, optional) This helps resolve conflicts between permissions assigned by the same
404-
* administrator. Default - current time
405-
* ,...
406-
* }
407-
* ,...
408-
* }
409-
* ,...
410-
* }
360+
* 1. transactions (array, required) A json array of json objects
361+
* [
362+
* {
363+
* "txid":"id", (string, required) The transaction id
364+
* "vout":n (numeric, required) The output number
365+
* "scriptPubKey": "hex", (string, optional) script key, used if cache=true or action=sign
366+
* "redeemScript": "hex" (string, optional) redeem script, used if action=sign
367+
* "cache":true|false (boolean, optional) If true - add cached script to tx, if omitted - add automatically if needed
368+
* }
369+
* ,...
370+
* ]
371+
* 2. addresses (object, required) a json object with addresses as keys and amounts as values
372+
* {
373+
* "address":
374+
* x.xxx (numeric, required) The key is the address, the value is the native currency amount
375+
* or
376+
* { (object) A json object of assets to send
377+
* "asset-identifier" : asset-quantity
378+
* ,...
379+
* }
380+
* or
381+
* { (object) A json object describing new asset issue
382+
* "issue" :
383+
* {
384+
* "raw" : n (numeric, required) The asset total amount in raw units
385+
* ,...
386+
* }
387+
* ,...
388+
* }
389+
* or
390+
* { (object) A json object describing follow-on asset issue
391+
* "issuemore" :
392+
* {
393+
* "asset" : "asset-identifier"(string, required) Asset identifier - one of the following: issue txid. asset reference, asset name.
394+
* "raw" : n (numeric, required) The asset total amount in raw units
395+
* ,...
396+
* }
397+
* ,...
398+
* }
399+
* or
400+
* { (object) A json object describing permission change
401+
* "permissions" :
402+
* {
403+
* "type" : "permission(s)" (string,required) Permission strings, comma delimited. Possible values:
404+
* connect,send,receive,issue,mine,admin,activate,create
405+
* "startblock" : n (numeric, optional) Block to apply permissions from (inclusive). Default - 0
406+
* "endblock" : n (numeric, optional) Block to apply permissions to (exclusive). Default - 4294967295
407+
* "timestamp" : n (numeric, optional) This helps resolve conflicts between
408+
* permissions assigned by the same administrator. Default - current time
409+
* ,...
410+
* }
411+
* ,...
412+
* }
413+
* ,...
414+
* }
415+
* 3. data (array, optional) Array of hexadecimal strings or data objects, see help appendrawdata for details.
416+
* 4."action" (string, optional, default "") Additional actions: "lock", "sign", "lock,sign", "sign,lock", "send".
411417
*
412418
* Result:
413-
* "transaction" (string) hex string of the transaction
419+
* "transaction" (string) hex string of the transaction (if action= "" or "lock")
420+
* or
421+
* { (object) A json object (if action= "sign" or "lock,sign" or "sign,lock")
422+
* "hex": "value", (string) The raw transaction with signature(s) (hex-encoded string)
423+
* "complete": true|false (boolean) if transaction has a complete set of signature (0 if not)
424+
* }
425+
* or
426+
* "hex" (string) The transaction hash in hex (if action= "send")
414427
*
415428
* @param txids
416429
* @param vouts
@@ -419,17 +432,22 @@ public String createRawSendFrom(String address, List<RawParam> rawParams) throws
419432
* @return
420433
* @throws MultichainException
421434
*/
422-
public String createRawTransaction(List<TxIdVout> inputs, List<AddressBalanceAsset> addessAssets)
435+
public String createRawTransaction(List<TxIdVout> inputs, List<AddressBalance> addessBalances, List<String> hexMetaData)
423436
throws MultichainException {
424437
String createTransactionRAW = new String();
425438

426-
Object objectTransactionRAW = executeCreateRawTransaction(inputs, addessAssets);
439+
Object objectTransactionRAW = executeCreateRawTransaction(inputs, addessBalances, hexMetaData);
427440
if (verifyInstance(objectTransactionRAW, String.class)) {
428441
createTransactionRAW = (String) objectTransactionRAW;
429442
}
430443

431444
return createTransactionRAW;
432445
}
446+
447+
public String createRawTransaction(List<TxIdVout> inputs, List<AddressBalance> addessBalances)
448+
throws MultichainException {
449+
return createRawTransaction(inputs, addessBalances, null);
450+
}
433451

434452
/**
435453
*

src/main/java/multichain/command/builders/QueryBuilderCommon.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ protected StringEntity prepareRpcEntity(Map<String, Object> entityValues) throws
194194

195195
private Object executeRequest() throws IOException, ClientProtocolException, MultichainException {
196196
CloseableHttpResponse response = httpclient.execute(httppost);
197-
int statusCode = response.getStatusLine().getStatusCode();
198-
if (statusCode >= 400) {
199-
EntityUtils.consume(response.getEntity());
200-
throw new MultichainException("code :" + statusCode, "message : " + response.getStatusLine().getReasonPhrase());
201-
}
197+
// int statusCode = response.getStatusLine().getStatusCode();
198+
// if (statusCode >= 400) {
199+
// EntityUtils.consume(response.getEntity());
200+
// throw new MultichainException("code :" + statusCode, "message : " + response.getStatusLine().getReasonPhrase());
201+
// }
202202
HttpEntity entity = response.getEntity();
203203

204204
String rpcAnswer = EntityUtils.toString(entity);

src/main/java/multichain/command/builders/QueryBuilderRAWTransaction.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
*/
88
package multichain.command.builders;
99

10+
import java.util.ArrayList;
1011
import java.util.HashMap;
1112
import java.util.List;
1213
import java.util.Map;
1314

1415
import multichain.command.MultichainException;
1516
import multichain.command.tools.MultichainTestParameter;
16-
import multichain.object.AddressBalanceAsset;
17+
import multichain.object.AddressBalance;
1718
import multichain.object.queryobjects.RawParam;
1819
import multichain.object.queryobjects.TxIdVout;
1920

@@ -273,7 +274,7 @@ protected Object executeCreateRawSendFrom(String address, List<RawParam> rawPara
273274
* @return
274275
* @throws MultichainException
275276
*/
276-
protected Object executeCreateRawTransaction(List<TxIdVout> inputs, List<AddressBalanceAsset> addessAssets)
277+
protected Object executeCreateRawTransaction(List<TxIdVout> inputs, List<AddressBalance> addessBalances, List<String> hexMetaData)
277278
throws MultichainException {
278279
if (inputs == null || inputs.isEmpty()) {
279280
throw new MultichainException("inputs", "inputs needed to create a RAW Transaction");
@@ -282,15 +283,22 @@ protected Object executeCreateRawTransaction(List<TxIdVout> inputs, List<Address
282283
input.isFilled();
283284
}
284285

285-
if (addessAssets == null || addessAssets.isEmpty()) {
286-
throw new MultichainException("Address Assets", "Address Assets needed to create a RAW Transaction");
286+
if (addessBalances == null || addessBalances.isEmpty()) {
287+
throw new MultichainException("Address Balance", "Address Balance needed to create a RAW Transaction");
287288
}
288-
for (AddressBalanceAsset addressAsset : addessAssets) {
289-
addressAsset.isFilled();
289+
Map<String, Object> mapOuput = new HashMap<String, Object>();
290+
for (AddressBalance addessBalance : addessBalances) {
291+
addessBalance.isFilled();
292+
mapOuput.put(addessBalance.getAddress(), addessBalance.getValue());
293+
}
294+
295+
if (hexMetaData != null) {
296+
return execute(CommandEnum.CREATERAWTRANSACTION, inputs, mapOuput, hexMetaData);
297+
} else {
298+
return execute(CommandEnum.CREATERAWTRANSACTION, inputs, mapOuput);
290299
}
291-
292-
return execute(CommandEnum.CREATERAWTRANSACTION, formatJson(inputs), formatJson(addessAssets));
293300
}
301+
294302

295303
/**
296304
*

src/main/java/multichain/command/builders/QueryBuilderWalletTransaction.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,6 @@ protected Object executeSendWithMetaDataFrom(String fromAddress, String toAddres
565565
if (assets == null || assets.isEmpty()) {
566566
throw new MultichainException("assets", "assets needed to be sent");
567567
}
568-
for (BalanceAssetBase asset : assets) {
569-
asset.isFilled();
570-
}
571568
Map<String, Double> mapAssets = new HashMap<String, Double>();
572569
for (BalanceAssetBase asset : assets) {
573570
asset.isFilled();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
*
3+
*/
4+
package multichain.object;
5+
6+
import multichain.command.MultichainException;
7+
8+
/**
9+
* @author Ub - H. Marteau
10+
* @version 4.10
11+
*
12+
*/
13+
public interface AddressBalance {
14+
public String getAddress();
15+
public void isFilled() throws MultichainException;
16+
public Object getValue() throws MultichainException;
17+
}

src/main/java/multichain/object/AddressBalanceAsset.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88
package multichain.object;
99

1010
import java.util.ArrayList;
11+
import java.util.HashMap;
1112
import java.util.List;
13+
import java.util.Map;
1214

1315
import multichain.command.MultichainException;
1416
import multichain.command.tools.MultichainTestParameter;
1517

1618
/**
1719
* @author Ub - H. MARTEAU
18-
* @version 1.0
20+
* @version 4.10
1921
*/
20-
public class AddressBalanceAsset {
22+
public class AddressBalanceAsset implements AddressBalance {
2123
String address;
2224
List<BalanceAssetBase> assets;
2325

@@ -31,6 +33,16 @@ public void isFilled() throws MultichainException {
3133
asset.isFilled();
3234
}
3335
}
36+
37+
public Map<String, Double> getValue() throws MultichainException {
38+
Map<String, Double> mapAssets = new HashMap<String, Double>();
39+
for (BalanceAssetBase asset : assets) {
40+
asset.isFilled();
41+
mapAssets.put(asset.getName(), new Double(asset.getQty()));
42+
}
43+
return mapAssets;
44+
}
45+
3446

3547
/**
3648
* @return the address
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (C) 2017 Worldline, Inc.
3+
*
4+
* MultiChainJavaAPI code distributed under the GPLv3 license, see COPYING file.
5+
* https://github.com/SimplyUb/MultiChainJavaAPI/blob/master/LICENSE
6+
*
7+
*/
8+
package multichain.object;
9+
10+
import multichain.command.MultichainException;
11+
import multichain.command.tools.MultichainTestParameter;
12+
13+
/**
14+
* @author Ub - H. MARTEAU
15+
* @version 4.10
16+
*/
17+
public class AddressBalanceCurrency implements AddressBalance {
18+
String address;
19+
double currencyValue;
20+
21+
public AddressBalanceCurrency() {
22+
}
23+
24+
public void isFilled() throws MultichainException {
25+
MultichainTestParameter.isNotNullOrEmpty("address", address);
26+
MultichainTestParameter.valueIsNotNegative("currency value", currencyValue);
27+
}
28+
29+
public Double getValue() {
30+
return new Double(currencyValue);
31+
}
32+
33+
/**
34+
* @return the address
35+
*/
36+
public String getAddress() {
37+
return address;
38+
}
39+
40+
/**
41+
* @param address the address to set
42+
*/
43+
public void setAddress(String address) {
44+
this.address = address;
45+
}
46+
47+
/**
48+
* @return the currencyValue
49+
*/
50+
public double getCurrencyValue() {
51+
return currencyValue;
52+
}
53+
54+
/**
55+
* @param currencyValue the currencyValue to set
56+
*/
57+
public void setCurrencyValue(double currencyValue) {
58+
this.currencyValue = currencyValue;
59+
}
60+
61+
62+
63+
}

0 commit comments

Comments
 (0)