Skip to content

Commit bc7563d

Browse files
author
Hubert Marteau
committed
3.1 - Corrections in the integration of Stream functions
1 parent 4bdb3a4 commit bc7563d

File tree

7 files changed

+851
-43
lines changed

7 files changed

+851
-43
lines changed

src/multichain/command/GrantCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import multichain.object.formatters.GrantFormatter;
1717

1818
/**
19-
* @author Ub - H. MARTEAU
20-
* @version 3.0
19+
* @author Ub - H. MARTEAU & Jagrut KOSTI
20+
* @version 3.1
2121
*/
2222
public class GrantCommand extends QueryBuilderGrant {
2323

@@ -28,6 +28,7 @@ public class GrantCommand extends QueryBuilderGrant {
2828
public static byte MINE = QueryBuilderGrant.MINE;
2929
public static byte ACTIVATE = QueryBuilderGrant.ACTIVATE;
3030
public static byte ADMIN = QueryBuilderGrant.ADMIN;
31+
public static byte CREATE = QueryBuilderGrant.CREATE;
3132

3233
public static int WALLET = QueryBuilderGrant.WALLET;
3334
public static int WALLET_ISSUE = QueryBuilderGrant.WALLET_ISSUE;

src/multichain/command/StreamCommand.java

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.List;
1212

1313
import multichain.command.builders.QueryBuilderStream;
14+
import multichain.object.Stream;
15+
import multichain.object.StreamKey;
1416
import multichain.object.StreamKeyItem;
1517
import multichain.object.formatters.StreamFormatter;
1618

@@ -80,6 +82,217 @@ public String create(String streamName) throws MultichainException {
8082
return create(streamName, false);
8183
}
8284

85+
/**
86+
* liststreams (stream-identifier(s) verbose count start )
87+
* 1. "stream-identifier(s)" (string, optional, default=*, all streams) Stream identifier - one of the following:
88+
* issue txid, stream reference, stream name.
89+
* or
90+
* 1. stream-identifier(s) (array, optional) A json array of stream identifiers
91+
* 2. verbose (boolean, optional, default=false) If true, returns stream list of creators
92+
* 3. count (number, optional, default=INT_MAX - all) The number of streams to display
93+
* 4. start (number, optional, default=-count - last) Start from specific stream, 0 based, if negative - from the
94+
* end
95+
*
96+
* Returns list of defined streams
97+
*
98+
* @param streamName
99+
* @param verbose
100+
* @param count
101+
* @param start
102+
* @return
103+
* @throws MultichainException
104+
*/
105+
@SuppressWarnings("unchecked")
106+
public List<Stream> listStreams(String streamName, boolean verbose, int count, int start)
107+
throws MultichainException {
108+
List<Stream> streams = new ArrayList<Stream>();
109+
110+
Object objectStreams = executeListStreams(streamName, verbose, count, start);
111+
if (verifyInstance(objectStreams, ArrayList.class)
112+
&& verifyInstanceofList((ArrayList<Object>) objectStreams, Stream.class)) {
113+
streams = StreamFormatter.formatStreams((ArrayList<Object>) objectStreams);
114+
}
115+
116+
return streams;
117+
}
118+
119+
/**
120+
* {@link #listStreams(String, boolean, int, int)} without start
121+
*
122+
* @param streamName
123+
* @param verbose
124+
* @param count
125+
* @return
126+
* @throws MultichainException
127+
*/
128+
@SuppressWarnings("unchecked")
129+
public List<Stream> listStreams(String streamName, boolean verbose, int count) throws MultichainException {
130+
List<Stream> streams = new ArrayList<Stream>();
131+
132+
Object objectStreams = executeListStreams(streamName, verbose, count);
133+
if (verifyInstance(objectStreams, ArrayList.class)
134+
&& verifyInstanceofList((ArrayList<Object>) objectStreams, Stream.class)) {
135+
streams = StreamFormatter.formatStreams((ArrayList<Object>) objectStreams);
136+
}
137+
138+
return streams;
139+
140+
}
141+
142+
/**
143+
* {@link #listStreams(String, boolean, int, int)} without start and default count = 10
144+
*
145+
* @param streamName
146+
* @param verbose
147+
* @return
148+
* @throws MultichainException
149+
*/
150+
@SuppressWarnings("unchecked")
151+
public List<Stream> listStreams(String streamName, boolean verbose) throws MultichainException {
152+
List<Stream> streams = new ArrayList<Stream>();
153+
154+
Object objectStreams = executeListStreams(streamName, verbose, 10);
155+
if (verifyInstance(objectStreams, ArrayList.class)
156+
&& verifyInstanceofList((ArrayList<Object>) objectStreams, Stream.class)) {
157+
streams = StreamFormatter.formatStreams((ArrayList<Object>) objectStreams);
158+
}
159+
160+
return streams;
161+
162+
}
163+
164+
/**
165+
* {@link #listStreams(String, boolean, int, int)} without start and default count = 10 and defautl verbose = false
166+
*
167+
* @param streamName
168+
* @return
169+
* @throws MultichainException
170+
*/
171+
@SuppressWarnings("unchecked")
172+
public List<Stream> listStreams(String streamName) throws MultichainException {
173+
List<Stream> streams = new ArrayList<Stream>();
174+
175+
Object objectStreams = executeListStreams(streamName, false, 10);
176+
if (verifyInstance(objectStreams, ArrayList.class)
177+
&& verifyInstanceofList((ArrayList<Object>) objectStreams, Stream.class)) {
178+
streams = StreamFormatter.formatStreams((ArrayList<Object>) objectStreams);
179+
}
180+
181+
return streams;
182+
183+
}
184+
185+
/**
186+
* liststreamkeys "stream-identifier" ( key(s) verbose count start local-ordering )
187+
*
188+
* Returns stream keys.
189+
*
190+
* Arguments:
191+
* 1. "stream-identifier"(string, required) Stream identifier - one of the following: stream txid, stream reference,
192+
* stream name.
193+
* 2. "key" (string, optional, default=*) Stream key
194+
* or
195+
* 2. key(s) (array, optional) A json array of stream keys
196+
* 3. verbose (boolean, optional, default=false) If true, returns extended information about key
197+
* 4. count (number, optional, default=INT_MAX - all) The number of items to display
198+
* 5. start (number, optional, default=-count - last) Start from specific item, 0 based, if negative - from the end
199+
* 6. local-ordering (boolean, optional, default=false) If true, items appear in the order they were processed by
200+
* the wallet, if false - in the order they apppear in blockchain
201+
*
202+
* Result:
203+
* "stream-keys" (array) List of stream keys.
204+
*
205+
* @param streamName
206+
* @param key
207+
* @param verbose
208+
* @param count
209+
* @param start
210+
* @return
211+
* @throws MultichainException
212+
*/
213+
@SuppressWarnings("unchecked")
214+
public List<StreamKey> listStreamKeys(String streamName, String key, boolean verbose, int count, int start)
215+
throws MultichainException {
216+
List<StreamKey> streamKeys = new ArrayList<StreamKey>();
217+
218+
Object objectStreamKeys = executeListStreamKeys(streamName, key, verbose, count, start);
219+
if (verifyInstance(objectStreamKeys, ArrayList.class)
220+
&& verifyInstanceofList((ArrayList<Object>) objectStreamKeys, StreamKey.class)) {
221+
streamKeys = StreamFormatter.formatStreamKeys((ArrayList<Object>) objectStreamKeys);
222+
}
223+
224+
return streamKeys;
225+
}
226+
227+
/**
228+
* {@link listStreamKeys(String streamName, String key, boolean verbose, int count, int start)} without start
229+
*
230+
* @param streamName
231+
* @param key
232+
* @param verbose
233+
* @param count
234+
* @return
235+
* @throws MultichainException
236+
*/
237+
@SuppressWarnings("unchecked")
238+
public List<StreamKey> listStreamKeys(String streamName, String key, boolean verbose, int count)
239+
throws MultichainException {
240+
List<StreamKey> streamKeys = new ArrayList<StreamKey>();
241+
242+
Object objectStreamKeys = executeListStreamKeys(streamName, key, verbose, count);
243+
if (verifyInstance(objectStreamKeys, ArrayList.class)
244+
&& verifyInstanceofList((ArrayList<Object>) objectStreamKeys, StreamKey.class)) {
245+
streamKeys = StreamFormatter.formatStreamKeys((ArrayList<Object>) objectStreamKeys);
246+
}
247+
248+
return streamKeys;
249+
}
250+
251+
/**
252+
* {@link listStreamKeys(String streamName, String key, boolean verbose, int count, int start)} without start, with
253+
* count = 10
254+
*
255+
* @param streamName
256+
* @param key
257+
* @param verbose
258+
* @param count
259+
* @return
260+
* @throws MultichainException
261+
*/
262+
public List<StreamKey> listStreamKeys(String streamName, String key, boolean verbose) throws MultichainException {
263+
return listStreamKeys(streamName, key, verbose, 10);
264+
}
265+
266+
/**
267+
* {@link listStreamKeys(String streamName, String key, boolean verbose, int count, int start)} without start, with
268+
* count = 10, verbse = false
269+
*
270+
* @param streamName
271+
* @param key
272+
* @param verbose
273+
* @param count
274+
* @return
275+
* @throws MultichainException
276+
*/
277+
public List<StreamKey> listStreamKeys(String streamName, String key) throws MultichainException {
278+
return listStreamKeys(streamName, key, false, 10);
279+
}
280+
281+
/**
282+
* {@link listStreamKeys(String streamName, String key, boolean verbose, int count, int start)} without start, with
283+
* count = 10, verbse = false, keys = "*"
284+
*
285+
* @param streamName
286+
* @param key
287+
* @param verbose
288+
* @param count
289+
* @return
290+
* @throws MultichainException
291+
*/
292+
public List<StreamKey> listStreamKeys(String streamName) throws MultichainException {
293+
return listStreamKeys(streamName, "*", false, 10);
294+
}
295+
83296
/**
84297
* liststreamkeyitems "stream-identifier" "key" ( verbose count start
85298
* local-ordering )
@@ -272,4 +485,25 @@ public void subscribe(String streamName) throws MultichainException {
272485
executeSubscribe(streamName);
273486
}
274487

488+
/**
489+
* unsubscribe entity-identifier(s)
490+
*
491+
* Unsubscribes from the stream.
492+
*
493+
* Arguments:
494+
* 1. "stream-identifier" (string, required) Stream identifier - one of the following: stream txid, stream
495+
* reference, stream name.
496+
* or
497+
* 1. "asset-identifier" (string, required) Asset identifier - one of the following: asset txid, asset reference,
498+
* asset name.
499+
* or
500+
* 1. entity-identifier(s) (array, optional) A json array of stream or asset identifiers
501+
*
502+
* @param streamName
503+
* @throws MultichainException
504+
*/
505+
public void unsubscribe(String streamName) throws MultichainException {
506+
executeUnsubscribe(streamName);
507+
}
508+
275509
}

src/multichain/command/builders/QueryBuilderCommon.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
import com.google.gson.internal.LinkedTreeMap;
3737

3838
/**
39-
* @author Ub - H. MARTEAU
40-
* @version 3.0
39+
* @author Ub - H. MARTEAU & Jagrut KOSTI
40+
* @version 3.1
4141
*/
4242
abstract class QueryBuilderCommon extends GsonFormatters {
4343

@@ -54,6 +54,7 @@ protected enum CommandEnum
5454
CLEARMEMPOOL,
5555
COMBINEUNPSENT,
5656
CREATE,
57+
CREATEFROM,
5758
CREATEMULTISIG,
5859
CREATERAWEXCHANGE,
5960
CREATERAWSENDFROM,
@@ -77,9 +78,11 @@ protected enum CommandEnum
7778
GETRAWCHANGEADDRESS,
7879
GETPEERINFO,
7980
GETRAWTRANSACTION,
81+
GETSTREAMITEM,
8082
GETTOTALBALANCES,
8183
GETTRANSACTION,
8284
GETTXOUT,
85+
GETTXOUTDATA,
8386
GETUNCONFIRMEDBALANCE,
8487
GETWALLETTRANSACTION,
8588
GRANT,
@@ -97,7 +100,12 @@ protected enum CommandEnum
97100
LISTASSETS,
98101
LISTLOCKUNPSENT,
99102
LISTPERMISSIONS,
103+
LISTSTREAMITEMS,
100104
LISTSTREAMKEYITEMS,
105+
LISTSTREAMKEYS,
106+
LISTSTREAMPUBLISHERS,
107+
LISTSTREAMPUBLISHERITEMS,
108+
LISTSTREAMS,
101109
LISTUNSPENT,
102110
LISTWALLETTRANSACTIONS,
103111
LOCKUNSPENT,
@@ -106,6 +114,7 @@ protected enum CommandEnum
106114
PREPARELOCKUNSPENT,
107115
PREPARELOCKUNSPENTFROM,
108116
PUBLISH,
117+
PUBLISHFROM,
109118
RESUME,
110119
REVOKE,
111120
REVOKEFROM,
@@ -122,6 +131,7 @@ protected enum CommandEnum
122131
SIGNRAWTRANSACTION,
123132
STOP,
124133
SUBSCRIBE,
134+
UNSUBSCRIBE,
125135
VALIDATEADDRESS,
126136
VERIFYMESSAGE
127137
}
@@ -140,7 +150,7 @@ protected void initialize(String ip, String port, String login, String password)
140150
/**
141151
*
142152
* @param command
143-
* @param parameter
153+
* @param parameters
144154
*
145155
* @return
146156
*

src/multichain/command/builders/QueryBuilderGrant.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
import multichain.command.tools.MultichainTestParameter;
1212

1313
/**
14-
* @author Ub - H. MARTEAU
15-
* @version 3.0
14+
* @author Ub - H. MARTEAU & Jagrut KOSTI
15+
* @version 3.1
1616
*/
1717
public class QueryBuilderGrant extends QueryBuilderCommon {
1818

19-
protected static byte CONNECT = (byte) 0b0000001;
20-
protected static byte SEND = (byte) 0b0000010;
21-
protected static byte RECEIVE = (byte) 0b0000100;
22-
protected static byte ISSUE = (byte) 0b0001000;
23-
protected static byte MINE = (byte) 0b0010000;
24-
protected static byte ACTIVATE = (byte) 0b0100000;
25-
protected static byte ADMIN = (byte) 0b1000000;
19+
protected static byte CONNECT = (byte) 0b00000001;
20+
protected static byte SEND = (byte) 0b00000010;
21+
protected static byte RECEIVE = (byte) 0b00000100;
22+
protected static byte ISSUE = (byte) 0b00001000;
23+
protected static byte MINE = (byte) 0b00010000;
24+
protected static byte ACTIVATE = (byte) 0b00100000;
25+
protected static byte ADMIN = (byte) 0b01000000;
26+
protected static byte CREATE = (byte) 0b10000000;
2627

2728
protected static int WALLET = CONNECT | SEND | RECEIVE;
2829
protected static int WALLET_ISSUE = WALLET | ISSUE;
@@ -34,6 +35,7 @@ public class QueryBuilderGrant extends QueryBuilderCommon {
3435
private static String MINE_STR = "mine";
3536
private static String ACTIVATE_STR = "activate";
3637
private static String ADMIN_STR = "admin";
38+
private static String CREATE_STR = "create";
3739

3840
private static String formatPermissionsList(int permissions) {
3941
String permissionsFormated = "";
@@ -77,6 +79,13 @@ private static String formatPermissionsList(int permissions) {
7779
}
7880
permissionsFormated = permissionsFormated.concat(ADMIN_STR);
7981
}
82+
if ((permissions & CREATE) > 0) {
83+
if (permissionsFormated.length() > 0) {
84+
permissionsFormated = permissionsFormated.concat(",");
85+
}
86+
permissionsFormated = permissionsFormated.concat(CREATE_STR);
87+
}
88+
8089
return permissionsFormated;
8190
}
8291

0 commit comments

Comments
 (0)