Skip to content

Commit cdfc8de

Browse files
committed
Add GrantWrite(From) (grant permission to write in a stream)
1 parent 7f78de5 commit cdfc8de

File tree

3 files changed

+180
-78
lines changed

3 files changed

+180
-78
lines changed

src/main/java/multichain/command/GrantCommand.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,80 @@ public String grantFrom(String addressFrom, String address, int permissions) thr
233233

234234
return grant;
235235
}
236+
/**
237+
* Grant permission to write in a stream to addresses
238+
*
239+
* @param address
240+
* (Address) The addresses to grant permission to
241+
* @param streamName
242+
* (String) The name of the stream
243+
* @return transactionId of grant action
244+
* @throws MultichainException
245+
*/
246+
public String grantWrite(Address address, String streamName) throws MultichainException {
247+
return grantWrite(address.getAddress(),streamName);
248+
}
249+
250+
/**
251+
* {@link #grantWrite(Address, byte)} with address in format String
252+
*
253+
* @param address
254+
* (String) The addresses to grant permission to
255+
* @param streamName
256+
* (String) The name of the stream
257+
* @return transactionId of grant action
258+
* @throws MultichainException
259+
*/
260+
public String grantWrite(String address, String streamName) throws MultichainException {
261+
String grantWrite = "";
236262

263+
Object objectGrant = executeGrantWrite(address, streamName);
264+
if (verifyInstance(objectGrant, String.class)) {
265+
grantWrite = (String) objectGrant;
266+
}
267+
268+
return grantWrite;
269+
}
270+
/**
271+
* {@link #grantWrite(Address, byte)} with control over the from-address used to
272+
* used to grant
273+
*
274+
* @param addressFrom
275+
* (Address) The from-address used to publish
276+
* @param address
277+
* (Address) The addresses to grant permission to
278+
* @param streamName
279+
* (String) The name of the stream
280+
* @return transactionId of grant action
281+
* @throws MultichainException
282+
*/
283+
public String grantWriteFrom(Address addressFrom, Address address, String streamName) throws MultichainException {
284+
return grantWriteFrom(addressFrom.getAddress(), address.getAddress(), streamName);
285+
}
286+
287+
/**
288+
* {@link #grantWrite(Address, Address, byte)} with addresses in format String
289+
*
290+
* @param addressFrom
291+
* (Address) The from-address used to publish
292+
* @param address
293+
* (String) The addresses to grant permission to
294+
* @param streamName
295+
* (String) The name of the stream
296+
* @return transactionId of grant action
297+
* @throws MultichainException
298+
*/
299+
public String grantWriteFrom(String addressFrom, String address, String streamName) throws MultichainException {
300+
String grantWrite = "";
301+
302+
Object objectGrant = executeGrantWriteFrom(addressFrom, address, streamName);
303+
if (verifyInstance(objectGrant, String.class)) {
304+
grantWrite = (String) objectGrant;
305+
}
306+
307+
return grantWrite;
308+
}
309+
237310
/**
238311
* listpermissions ("permission(s)" "address" verbose)
239312
*

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,16 +555,11 @@ public String publish(String streamName, String key, String dataHex) throws Mult
555555
*/
556556

557557
public String publishFrom(Address addressFrom, String streamName, String key, String dataHex) throws MultichainException {
558-
String stringPublish = "";
559-
Object objectPublish = executePublishFrom(addressFrom.getAddress(), streamName, key, dataHex);
560-
if (verifyInstance(objectPublish, String.class)) {
561-
stringPublish = (String) objectPublish;
562-
}
563-
return stringPublish;
558+
return publishFrom(addressFrom.getAddress(), streamName, key, dataHex);
564559
}
565560

566561
/**
567-
* {@link #createFrom(Address, String, String, String)} with address in format string
562+
* {@link #PublishFrom(Address, String, String, String)} with address in format string
568563
*
569564
* @param addressFrom
570565
* (String) The from-address used to publish

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

Lines changed: 105 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,32 @@ private static String formatPermissionsList(int permissions) {
9292
/**
9393
* Grants permissions to addresses
9494
*
95-
* grant "address(es)" "permission(s)" ( native-amount "comment" "comment-to" startblock endblock )
95+
* grant "address(es)" "permission(s)" ( native-amount "comment" "comment-to"
96+
* startblock endblock )
9697
*
9798
* Grant permission(s) to a given address.
9899
*
99-
* Arguments:
100-
* 1. "address(es)" (string, required) The multichain addresses to send to (comma delimited)
101-
* 2. "permission(s)" (string, required) Permission strings, comma delimited. Possible values:
102-
* connect,send,receive,issue,mine,admin,activate
103-
* 3. "native-amount" (numeric, optional) native currency amount to send. eg 0.1. Default - 0.0
104-
* 4. "startblock" (numeric, optional) Block to apply permissions from (inclusive). Default - 0
105-
* 5. "endblock" (numeric, optional) Block to apply permissions to (exclusive). Default - 4294967295
106-
* If -1 is specified default value is used.
107-
* 6. "comment" (string, optional) A comment used to store what the transaction is for.
108-
* This is not part of the transaction, just kept in your wallet.
109-
* 7. "comment-to" (string, optional) A comment to store the name of the person or organization
110-
* to which you're sending the transaction. This is not part of the
100+
* Arguments: 1. "address(es)" (string, required) The multichain addresses to
101+
* send to (comma delimited) 2. "permission(s)" (string, required) Permission
102+
* strings, comma delimited. Possible values:
103+
* connect,send,receive,issue,mine,admin,activate 3. "native-amount" (numeric,
104+
* optional) native currency amount to send. eg 0.1. Default - 0.0 4.
105+
* "startblock" (numeric, optional) Block to apply permissions from (inclusive).
106+
* Default - 0 5. "endblock" (numeric, optional) Block to apply permissions to
107+
* (exclusive). Default - 4294967295 If -1 is specified default value is used.
108+
* 6. "comment" (string, optional) A comment used to store what the transaction
109+
* is for. This is not part of the transaction, just kept in your wallet. 7.
110+
* "comment-to" (string, optional) A comment to store the name of the person or
111+
* organization to which you're sending the transaction. This is not part of the
111112
* transaction, just kept in your wallet.
112113
*
113-
* Result:
114-
* "transactionid" (string) The transaction id.
114+
* Result: "transactionid" (string) The transaction id.
115115
*
116116
*
117117
* @param address
118118
* @param permissions
119-
* This permissions will be grant to all addresses who are send
120-
* in parameter
119+
* This permissions will be grant to all addresses who are send in
120+
* parameter
121121
* @return the txid of the transaction granting the permissions
122122
* @throws MultichainException
123123
*/
@@ -133,37 +133,36 @@ protected Object executeGrant(String address, int permissions) throws Multichain
133133
/**
134134
* Grants permissions to addresses From an address
135135
*
136-
* grantfrom "from-address" "to-address(es)" "permission(s)" ( native-amount "comment" "comment-to" startblock
137-
* endblock )
136+
* grantfrom "from-address" "to-address(es)" "permission(s)" ( native-amount
137+
* "comment" "comment-to" startblock endblock )
138138
*
139139
* Grant permission using specific address.
140140
*
141-
* Arguments:
142-
* 1. "from-address" (string, required) Address used for grant.
143-
* 2. "to-address(es)" (string, required) The multichain addresses to grant permissions to
144-
* 3. "permission(s)" (string, required) Permission strings, comma delimited. Possible values:
145-
* connect,send,receive,issue,mine,admin,activate
146-
* 4. "native-amount" (numeric, optional) native currency amount to send. eg 0.1. Default - 0.0
147-
* 5. "startblock" (numeric, optional) Block to apply permissions from (inclusive). Default - 0
148-
* 6. "endblock" (numeric, optional) Block to apply permissions to (exclusive). Default - 4294967295
149-
* If -1 is specified default value is used.
150-
* 7. "comment" (string, optional) A comment used to store what the transaction is for.
151-
* This is not part of the transaction, just kept in your wallet.
152-
* 8. "comment-to" (string, optional) A comment to store the name of the person or organization
153-
* to which you're sending the transaction. This is not part of the
141+
* Arguments: 1. "from-address" (string, required) Address used for grant. 2.
142+
* "to-address(es)" (string, required) The multichain addresses to grant
143+
* permissions to 3. "permission(s)" (string, required) Permission strings,
144+
* comma delimited. Possible values:
145+
* connect,send,receive,issue,mine,admin,activate 4. "native-amount" (numeric,
146+
* optional) native currency amount to send. eg 0.1. Default - 0.0 5.
147+
* "startblock" (numeric, optional) Block to apply permissions from (inclusive).
148+
* Default - 0 6. "endblock" (numeric, optional) Block to apply permissions to
149+
* (exclusive). Default - 4294967295 If -1 is specified default value is used.
150+
* 7. "comment" (string, optional) A comment used to store what the transaction
151+
* is for. This is not part of the transaction, just kept in your wallet. 8.
152+
* "comment-to" (string, optional) A comment to store the name of the person or
153+
* organization to which you're sending the transaction. This is not part of the
154154
* transaction, just kept in your wallet.
155155
*
156-
* Result:
157-
* "transactionid" (string) The transaction id.
156+
* Result: "transactionid" (string) The transaction id.
158157
*
159158
*
160159
* @param addressFrom
161160
* address origin
162161
* @param address
163162
* address destination
164163
* @param permissions
165-
* This permissions will be grant to all addresses who are send
166-
* in parameter
164+
* This permissions will be grant to all addresses who are send in
165+
* parameter
167166
* @return the txid of the transaction granting the permissions
168167
* @throws MultichainException
169168
*/
@@ -177,17 +176,54 @@ protected Object executeGrantFrom(String addressFrom, String address, int permis
177176
return execute(CommandEnum.GRANTFROM, addressFrom, address, permissionsFormated);
178177
}
179178

179+
/**
180+
* Grant permission to write in a stream to addresses
181+
*
182+
* @param address
183+
* (String) The addresses to grant permission to
184+
* @param streamName
185+
* (String) The name of the stream
186+
* @return (String) The transaction id
187+
* @throws MultichainException
188+
*/
189+
protected Object executeGrantWrite(String address, String streamName) throws MultichainException {
190+
MultichainTestParameter.isNotNullOrEmpty("address", address);
191+
MultichainTestParameter.isNotNullOrEmpty("stream", streamName);
192+
return execute(CommandEnum.GRANT, address, streamName + ".write");
193+
}
194+
195+
196+
/**
197+
* {@link #executeGrantWrite(String, String)} with control over the
198+
* from-address used to grant
199+
*
200+
* @param addressFrom
201+
* (String) The from-address used to grant
202+
* @param address
203+
* (String) The addresses to grant permission to
204+
* @param streamName
205+
* (String) The name of the stream
206+
* @return (String) The transaction id
207+
* @throws MultichainException
208+
*/
209+
protected Object executeGrantWriteFrom(String addressFrom, String address, String streamName) throws MultichainException {
210+
MultichainTestParameter.isNotNullOrEmpty("addressFrom", addressFrom);
211+
MultichainTestParameter.isNotNullOrEmpty("address", address);
212+
MultichainTestParameter.isNotNullOrEmpty("stream", streamName);
213+
return execute(CommandEnum.GRANTFROM, addressFrom, address, streamName + ".write");
214+
}
215+
180216
/**
181217
*
182218
* listpermissions ("permission(s)" "address" verbose)
183219
*
184220
* Returns list of addresses having one of the specified permissions
185221
*
186-
* Arguments:
187-
* 1. "permission(s)" (string, optional) Permission strings, comma delimited. Possible values:
188-
* connect,send,receive,issue,mine,admin,activate. Default: all.
189-
* 2. "address" (string, optional) The addresses to retrieve permissions for. "" or "*" for all addresses
190-
* 3. verbose (boolean, optional, default=false) If true, returns list of pending grants
222+
* Arguments: 1. "permission(s)" (string, optional) Permission strings, comma
223+
* delimited. Possible values: connect,send,receive,issue,mine,admin,activate.
224+
* Default: all. 2. "address" (string, optional) The addresses to retrieve
225+
* permissions for. "" or "*" for all addresses 3. verbose (boolean, optional,
226+
* default=false) If true, returns list of pending grants
191227
*
192228
* @param permissions
193229
* @param address
@@ -220,24 +256,22 @@ protected Object executeListPermissions(int permissions, String address, boolean
220256
*
221257
* Revoke permission from a given address. The amount is a real
222258
*
223-
* Arguments:
224-
* 1. "address(es)" (string, required) The addresses(es) to revoke permissions from
225-
* 2. "permission(s)" (string, required) Permission strings, comma delimited. Possible values:
226-
* connect,send,receive,issue,mine,admin
227-
* 3. "native-amount" (numeric, optional) native currency amount to send. eg 0.1. Default - 0
228-
* 4. "comment" (string, optional) A comment used to store what the transaction is for.
229-
* This is not part of the transaction, just kept in your wallet.
230-
* 5. "comment-to" (string, optional) A comment to store the name of the person or organization
231-
* to which you're sending the transaction. This is not part of the
232-
* transaction, just kept in your wallet.
259+
* Arguments: 1. "address(es)" (string, required) The addresses(es) to revoke
260+
* permissions from 2. "permission(s)" (string, required) Permission strings,
261+
* comma delimited. Possible values: connect,send,receive,issue,mine,admin 3.
262+
* "native-amount" (numeric, optional) native currency amount to send. eg 0.1.
263+
* Default - 0 4. "comment" (string, optional) A comment used to store what the
264+
* transaction is for. This is not part of the transaction, just kept in your
265+
* wallet. 5. "comment-to" (string, optional) A comment to store the name of the
266+
* person or organization to which you're sending the transaction. This is not
267+
* part of the transaction, just kept in your wallet.
233268
*
234-
* Result:
235-
* "transactionid" (string) The transaction id.
269+
* Result: "transactionid" (string) The transaction id.
236270
*
237271
* @param address
238272
* @param permissions
239-
* This permissions will be grant to all addresses who are send
240-
* in parameter
273+
* This permissions will be grant to all addresses who are send in
274+
* parameter
241275
* @return the txid of the transaction revoking the permissions
242276
* @throws MultichainException
243277
*/
@@ -253,33 +287,33 @@ protected Object executeRevoke(String address, int permissions) throws Multichai
253287
/**
254288
* Revoke permissions to addresses From an address
255289
*
256-
* revokefrom "from-address" "to-address(es)" "permission(s)" ( native-amount "comment" "comment-to" )
290+
* revokefrom "from-address" "to-address(es)" "permission(s)" ( native-amount
291+
* "comment" "comment-to" )
257292
*
258293
* Revoke permissions using specific address.
259294
*
260-
* Arguments:
261-
* 1. "from-address" (string, required) Addresses used for revoke.
262-
* 2. "to-address(es)" (string, required) The addresses(es) to revoke permissions from. Comma delimited
263-
* 3. "permission(s)" (string, required) Permission strings, comma delimited. Possible values:
264-
* connect,send,receive,issue,mine,admin
265-
* 4. "native-amount" (numeric, optional) native currency amount to send. eg 0.1. Default - 0
266-
* 5. "comment" (string, optional) A comment used to store what the transaction is for.
267-
* This is not part of the transaction, just kept in your wallet.
268-
* 6. "comment-to" (string, optional) A comment to store the name of the person or organization
269-
* to which you're sending the transaction. This is not part of the
270-
* transaction, just kept in your wallet.
295+
* Arguments: 1. "from-address" (string, required) Addresses used for revoke. 2.
296+
* "to-address(es)" (string, required) The addresses(es) to revoke permissions
297+
* from. Comma delimited 3. "permission(s)" (string, required) Permission
298+
* strings, comma delimited. Possible values:
299+
* connect,send,receive,issue,mine,admin 4. "native-amount" (numeric, optional)
300+
* native currency amount to send. eg 0.1. Default - 0 5. "comment" (string,
301+
* optional) A comment used to store what the transaction is for. This is not
302+
* part of the transaction, just kept in your wallet. 6. "comment-to" (string,
303+
* optional) A comment to store the name of the person or organization to which
304+
* you're sending the transaction. This is not part of the transaction, just
305+
* kept in your wallet.
271306
*
272-
* Result:
273-
* "transactionid" (string) The transaction id.
307+
* Result: "transactionid" (string) The transaction id.
274308
*
275309
*
276310
* @param addressFrom
277311
* address origin
278312
* @param address
279313
* address destination
280314
* @param permissions
281-
* This permissions will be grant to all addresses who are send
282-
* in parameter
315+
* This permissions will be grant to all addresses who are send in
316+
* parameter
283317
* @return the txid of the transaction revoking the permissions
284318
* @throws MultichainException
285319
*/

0 commit comments

Comments
 (0)