Skip to content

Commit fe80382

Browse files
Add files via upload
1 parent c428cf8 commit fe80382

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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.command.builders;
9+
10+
import multichain.command.MultichainException;
11+
import multichain.command.tools.MultichainTestParameter;
12+
13+
/**
14+
* @author Ub - H. MARTEAU
15+
* @version 2.1
16+
*/
17+
public class QueryBuilderStream extends QueryBuilderCommon {
18+
/**
19+
* create stream "stream-name" open ( custom-fields )
20+
*
21+
* Creates stream
22+
*
23+
*
24+
* Arguments: 1. entity-type (string, required) The only possible value:
25+
* stream 2. "stream-name" (string, required) Stream name, if not "" should
26+
* be unique. 3. open (boolean, required) Allow anyone to publish in this
27+
* stream 4 custom-fields (object, optional) a json object with custom
28+
* fields { "param-name": "param-value" (strings, required) The key is the
29+
* parameter name, the value is parameter value ,... }
30+
*
31+
* Result: "transactionid" (string) The transaction id.
32+
*
33+
* @param streamName
34+
* @param open
35+
* @return TxId
36+
* @throws MultichainException
37+
*/
38+
protected String executeCreate(String streamName, boolean open) throws MultichainException {
39+
MultichainTestParameter.isNotNullOrEmpty("streamName", streamName);
40+
41+
return execute(CommandEnum.CREATE, formatJson("stream"), formatJson(streamName), formatJson(open));
42+
}
43+
44+
/**
45+
* liststreamkeyitems "stream-identifier" "key" ( verbose count start
46+
* local-ordering )
47+
*
48+
* Returns stream items for specific key.
49+
*
50+
* Arguments: 1. "stream-identifier"(string, required) Stream identifier -
51+
* one of the following: stream txid, stream reference, stream name. 2.
52+
* "key" (string, required) Stream key 3. verbose (boolean, optional,
53+
* default=false) If true, returns information about item transaction 4.
54+
* count (number, optional, default=10) The number of items to display 5.
55+
* start (number, optional, default=-count - last) Start from specific item,
56+
* 0 based, if negative - from the end 6. local-ordering (boolean, optional,
57+
* default=false) If true, items appear in the order they were processed by
58+
* the wallet, if false - in the order they appear in blockchain
59+
*
60+
* Result: "stream-items" (array) List of stream items for specific key.
61+
*
62+
* @param streamName
63+
* @param key
64+
* @param verbose
65+
* @param count
66+
* @param start
67+
* @return
68+
* @throws MultichainException
69+
*/
70+
protected String executeListStreamKeyItems(String streamName, String key, boolean verbose, int count, int start)
71+
throws MultichainException {
72+
MultichainTestParameter.isNotNullOrEmpty("streamName", streamName);
73+
MultichainTestParameter.isNotNullOrEmpty("key", key);
74+
MultichainTestParameter.valueIsPositive("count", count);
75+
MultichainTestParameter.valueIsPositive("start", start);
76+
77+
return execute(CommandEnum.PUBLISH, formatJson(streamName), formatJson(key), formatJson(count),
78+
formatJson(start));
79+
}
80+
81+
/**
82+
* publish "stream-identifier" "key" data-hex
83+
*
84+
* Publishes stream item
85+
*
86+
*
87+
* Arguments: 1. "stream-identifier" (string, required) Stream identifier -
88+
* one of the following: stream txid, stream reference, stream name. 2.
89+
* "key" (string, required) Item key 3. data-hex (string, required) Item
90+
* data hex string
91+
*
92+
* Result: "transactionid" (string) The transaction id.
93+
*
94+
* @param streamName
95+
* @param key
96+
* @param dataHex
97+
* : data in hexadecimal in string format
98+
* @return
99+
* @throws MultichainException
100+
*/
101+
protected String executePublish(String streamName, String key, String dataHex) throws MultichainException {
102+
MultichainTestParameter.isNotNullOrEmpty("streamName", streamName);
103+
MultichainTestParameter.isNotNullOrEmpty("key", key);
104+
MultichainTestParameter.isNotNullOrEmpty("dataHex", dataHex);
105+
106+
return execute(CommandEnum.PUBLISH, formatJson(streamName), formatJson(key), formatJson(dataHex));
107+
}
108+
109+
/**
110+
* subscribe entity-identifier(s) ( rescan )
111+
*
112+
* Subscribes to the stream.
113+
*
114+
* Arguments: 1. "stream-identifier" (string, required) Stream identifier -
115+
* one of the following: stream txid, stream reference, stream name. or 1.
116+
* "asset-identifier" (string, required) Asset identifier - one of the
117+
* following: asset txid, asset reference, asset name. or 1.
118+
* entity-identifier(s) (array, optional) A json array of stream or asset
119+
* identifiers 2. rescan (boolean, optional, default=true) Rescan the wallet
120+
* for transactions
121+
*
122+
* Note: This call can take minutes to complete if rescan is true.
123+
*
124+
* @param streamName
125+
* @throws MultichainException
126+
*/
127+
protected void executeSubscribe(String streamName) throws MultichainException {
128+
MultichainTestParameter.isNotNullOrEmpty("streamName", streamName);
129+
130+
execute(CommandEnum.SUBSCRIBE, formatJson(streamName));
131+
}
132+
}

0 commit comments

Comments
 (0)