Skip to content

Commit 9d3706e

Browse files
author
[a561842] Hubert Marteau
committed
1 parent 45b2d60 commit 9d3706e

File tree

6 files changed

+155
-8
lines changed

6 files changed

+155
-8
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.7-SNAPSHOT</version>
6+
<version>0.4.8-SNAPSHOT</version>
77

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

src/main/java/multichain/command/BlockCommand.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
*/
88
package multichain.command;
99

10+
import java.util.ArrayList;
11+
import java.util.List;
12+
import java.util.logging.Level;
13+
import java.util.logging.Logger;
1014
import multichain.command.builders.QueryBuilderBlock;
1115
import multichain.object.Block;
1216
import multichain.object.formatters.BlockFormatter;
1317

1418
/**
1519
* @author Ub - H. MARTEAU
16-
* @version 3.0
20+
* @version 4.8
1721
*/
1822
public class BlockCommand extends QueryBuilderBlock {
1923

@@ -91,6 +95,26 @@ public Block getBlock(String blockHash, boolean verbose) throws MultichainExcept
9195
return block;
9296
}
9397

98+
/****
99+
* added by leo
100+
* @param blockidentifiers
101+
* @param verbose
102+
* @return List<Block>
103+
*/
104+
public List<Block> listBlocksList(String blockidentifiers,boolean verbose){
105+
try {
106+
List<Block> blocks=new ArrayList<Block>();
107+
Object objectBlock=executeListBlocks(blockidentifiers,verbose);
108+
int size=((ArrayList)objectBlock).size();
109+
for(int a=0;a<size;a++){
110+
blocks.add(BlockFormatter.formatBlock(((ArrayList)objectBlock).get(a)));
111+
}
112+
return blocks;
113+
} catch (MultichainException ex) {
114+
Logger.getLogger(BlockCommand.class.getName()).log(Level.SEVERE, null, ex);
115+
}
116+
return null;
117+
}
94118
/**
95119
* {@link #getBlock(String, boolean)} without verbose
96120
*

src/main/java/multichain/command/StreamCommand.java

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import java.util.ArrayList;
1111
import java.util.List;
12+
import java.util.logging.Level;
13+
import java.util.logging.Logger;
1214

1315
import multichain.command.builders.QueryBuilderStream;
1416
import multichain.object.Address;
@@ -19,7 +21,7 @@
1921

2022
/**
2123
* @author Ub - H. MARTEAU
22-
* @version 1.1
24+
* @version 4.8
2325
*/
2426
public class StreamCommand extends QueryBuilderStream {
2527

@@ -82,7 +84,83 @@ public String create(String streamName, boolean open) throws MultichainException
8284
public String create(String streamName) throws MultichainException {
8385
return create(streamName, false);
8486
}
85-
87+
/*****
88+
* subscribe to a stream with rescan param
89+
* @param streamidentifier
90+
* @param rescan
91+
*/
92+
public void subscribe(String streamidentifier,boolean rescan) throws MultichainException{
93+
executeSubscribe(streamidentifier,rescan);
94+
}
95+
/****
96+
* list stream items for a stream
97+
* @param streanmane
98+
* @param verbose
99+
* @param count
100+
* @param start
101+
* @param localordering
102+
* @return
103+
*/
104+
public List<StreamKeyItem> listStreamItems(String streanmane,boolean verbose,int count,int start,boolean localordering){
105+
Object obj=null;
106+
try {
107+
obj = executeListStreamItems(streanmane,verbose,count,start,localordering);
108+
} catch (MultichainException ex) {
109+
Logger.getLogger(StreamCommand.class.getName()).log(Level.SEVERE, null, ex);
110+
}
111+
int size=((List)obj).size();
112+
StreamKeyItem item=null;
113+
List<StreamKeyItem> items=new ArrayList<StreamKeyItem>();
114+
for(int a=0;a<size;a++){
115+
item=StreamFormatter.formatStreamKeyItem(((List)obj).get(a));
116+
items.add(item);
117+
}
118+
return items;
119+
}
120+
/****
121+
* added by leo
122+
* return a specific item for a stream
123+
* @param streamname
124+
* @param txid
125+
* @param verbose
126+
* @return
127+
*/
128+
public StreamKeyItem getStreamItem(String streamname,String txid,boolean verbose){
129+
Object obj=null;
130+
StreamKeyItem item=null;
131+
try {
132+
obj=executeGetstreamitem(streamname,txid,verbose);
133+
} catch (MultichainException ex) {
134+
Logger.getLogger(StreamCommand.class.getName()).log(Level.SEVERE, null, ex);
135+
}
136+
if(verifyInstance(obj,com.google.gson.internal.LinkedTreeMap.class)){
137+
item=StreamFormatter.formatStreamKeyItem(obj);
138+
}
139+
if(item!=null){
140+
return item;
141+
}
142+
return null;
143+
}
144+
/**
145+
* **
146+
* get the latest key item for a specific stream
147+
*
148+
* @param streamname
149+
* @param key
150+
* @param verbose
151+
*
152+
* @return
153+
*/
154+
public StreamKeyItem getLatestStreamKeyItem(String streamname, String key, boolean verbose) throws MultichainException {
155+
StreamKeyItem result = new StreamKeyItem();
156+
Object obj = executeListStreamKeyItems(streamname, key, verbose, 1, -1);
157+
if (verifyInstance(obj, ArrayList.class) && verifyInstanceofList((ArrayList<Object>) obj, StreamKeyItem.class)) {
158+
if (StreamFormatter.formatStreamKeyItems((ArrayList<Object>) obj).size() > 0) {
159+
result = StreamFormatter.formatStreamKeyItems((ArrayList<Object>) obj).get(0);
160+
}
161+
}
162+
return result;
163+
}
86164
/**
87165
* {@link #create(String, boolean)} with control over the from-address used to
88166
* used to create the stream

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* @author Ub - H. MARTEAU
14-
* @version 3.0
14+
* @version 4.8
1515
*/
1616
public class QueryBuilderBlock extends QueryBuilderCommon {
1717

@@ -75,6 +75,16 @@ protected Object executeGetBlock(String hash, boolean verbose) throws Multichain
7575
return execute(CommandEnum.GETBLOCK, hash, verbose);
7676
}
7777

78+
/****
79+
* return blockList object for block identified by string with form like 12-13
80+
* @param blockidentifiers
81+
* @param verbose
82+
* @return Object
83+
* @throws MultichainException
84+
*/
85+
protected Object executeListBlocks(String blockidentifiers,boolean verbose) throws MultichainException{
86+
return execute(CommandEnum.LISTBLOCKS,blockidentifiers,verbose);
87+
}
7888
/**
7989
* getblock "hash/height" ( verbose )
8090
*

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
/**
4141
* @author Ub - H. MARTEAU & Jagrut KOSTI
42-
* @version 4.6
42+
* @version 4.8
4343
*/
4444
abstract class QueryBuilderCommon extends GsonFormatters {
4545

@@ -111,6 +111,7 @@ protected enum CommandEnum {
111111
LISTUNSPENT,
112112
LISTWALLETTRANSACTIONS,
113113
LOCKUNSPENT,
114+
LISTBLOCKS,
114115
PAUSE,
115116
PING,
116117
PREPARELOCKUNSPENT,

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @author Ub - H. MARTEAU & Jagrut KOSTI
15-
* @version 3.1
15+
* @version 4.8
1616
*/
1717
public class QueryBuilderStream extends QueryBuilderCommon {
1818
/**
@@ -402,5 +402,39 @@ protected void executeUnsubscribe(String streamName) throws MultichainException
402402

403403
execute(CommandEnum.UNSUBSCRIBE, streamName);
404404
}
405-
405+
406+
/****
407+
* subscribe address to stream with rescan param
408+
* @param streamname
409+
* @param rescan
410+
*/
411+
protected void executeSubscribe(String streamname,boolean rescan) throws MultichainException, MultichainException{
412+
MultichainTestParameter.isNotNullOrEmpty("streamname", streamname);
413+
execute(CommandEnum.SUBSCRIBE,streamname,rescan);
414+
}
415+
/****
416+
*
417+
* @param steamname
418+
* @param verbose
419+
* @param count
420+
* @param start
421+
* @param localordering
422+
* @return Object
423+
*/
424+
protected Object executeListStreamItems(String streamname,boolean verbose,int count,int start,boolean localordering) throws MultichainException{
425+
MultichainTestParameter.isNotNullOrEmpty("streamname", streamname);
426+
return execute(CommandEnum.LISTSTREAMITEMS,streamname,verbose,count,start,localordering);
427+
}
428+
/****
429+
*
430+
* @param streamname
431+
* @param txid
432+
* @param verbose
433+
* @return
434+
*/
435+
protected Object executeGetstreamitem(String streamname,String txid,boolean verbose) throws MultichainException{
436+
MultichainTestParameter.isNotNullOrEmpty("streamname", streamname);
437+
MultichainTestParameter.isNotNullOrEmpty("txid", txid);
438+
return execute(CommandEnum.GETSTREAMITEM,streamname,txid,verbose);
439+
}
406440
}

0 commit comments

Comments
 (0)