@@ -249,24 +249,31 @@ public void Execute(string cmd, Action<int, DataNode, bool> callback)
249
249
{
250
250
if ( args . Length == 5 )
251
251
{
252
- var data = Base16 . Decode ( args [ 3 ] ) ;
253
- var signatureKind = ( SignatureKind ) Enum . Parse ( typeof ( SignatureKind ) , args [ 4 ] , true ) ;
254
-
255
- SignData ( data , signatureKind , id , ( signature , random , txError ) => {
256
- if ( signature != null )
257
- {
258
- success = true ;
259
- answer = APIUtils . FromAPIResult ( new Signature ( ) { signature = signature , random = random } ) ;
260
- }
261
- else
262
- {
263
- answer = APIUtils . FromAPIResult ( new Error ( ) { message = txError } ) ;
264
- }
252
+ var data = Base16 . Decode ( args [ 3 ] , false ) ;
253
+ if ( data == null )
254
+ {
255
+ answer = APIUtils . FromAPIResult ( new Error ( ) { message = $ "signTx: Invalid input received" } ) ;
256
+ }
257
+ else
258
+ {
259
+ var signatureKind = ( SignatureKind ) Enum . Parse ( typeof ( SignatureKind ) , args [ 4 ] , true ) ;
265
260
266
- callback ( id , answer , success ) ;
267
- _isPendingRequest = false ;
268
- } ) ;
261
+ SignData ( data , signatureKind , id , ( signature , random , txError ) => {
262
+ if ( signature != null )
263
+ {
264
+ success = true ;
265
+ answer = APIUtils . FromAPIResult ( new Signature ( ) { signature = signature , random = random } ) ;
266
+ }
267
+ else
268
+ {
269
+ answer = APIUtils . FromAPIResult ( new Error ( ) { message = txError } ) ;
270
+ }
269
271
272
+ callback ( id , answer , success ) ;
273
+ _isPendingRequest = false ;
274
+ } ) ;
275
+ }
276
+
270
277
return ;
271
278
}
272
279
else
@@ -287,23 +294,31 @@ public void Execute(string cmd, Action<int, DataNode, bool> callback)
287
294
{
288
295
var nexus = args [ 1 ] ;
289
296
var chain = args [ 2 ] ;
290
- var script = Base16 . Decode ( args [ 3 ] ) ;
291
- byte [ ] payload = args [ 4 ] . Length > 0 ? Base16 . Decode ( args [ 4 ] ) : null ;
297
+ var script = Base16 . Decode ( args [ 3 ] , false ) ;
292
298
293
- SignTransaction ( nexus , chain , script , payload , id , ( hash , txError ) => {
294
- if ( hash != Hash . Null )
295
- {
296
- success = true ;
297
- answer = APIUtils . FromAPIResult ( new Transaction ( ) { hash = hash . ToString ( ) } ) ;
298
- }
299
- else
300
- {
301
- answer = APIUtils . FromAPIResult ( new Error ( ) { message = txError } ) ;
302
- }
299
+ if ( script == null )
300
+ {
301
+ answer = APIUtils . FromAPIResult ( new Error ( ) { message = $ "signTx: Invalid script data" } ) ;
302
+ }
303
+ else
304
+ {
305
+ byte [ ] payload = args [ 4 ] . Length > 0 ? Base16 . Decode ( args [ 4 ] , false ) : null ;
303
306
304
- callback ( id , answer , success ) ;
305
- _isPendingRequest = false ;
306
- } ) ;
307
+ SignTransaction ( nexus , chain , script , payload , id , ( hash , txError ) => {
308
+ if ( hash != Hash . Null )
309
+ {
310
+ success = true ;
311
+ answer = APIUtils . FromAPIResult ( new Transaction ( ) { hash = hash . ToString ( ) } ) ;
312
+ }
313
+ else
314
+ {
315
+ answer = APIUtils . FromAPIResult ( new Error ( ) { message = txError } ) ;
316
+ }
317
+
318
+ callback ( id , answer , success ) ;
319
+ _isPendingRequest = false ;
320
+ } ) ;
321
+ }
307
322
308
323
return ;
309
324
}
@@ -323,24 +338,31 @@ public void Execute(string cmd, Action<int, DataNode, bool> callback)
323
338
{
324
339
if ( args . Length == 4 )
325
340
{
326
- var script = Base16 . Decode ( args [ 1 ] ) ;
341
+ var script = Base16 . Decode ( args [ 1 ] , false ) ;
327
342
328
- InvokeScript ( script , id , ( invokeResult , invokeError ) =>
343
+ if ( script == null )
329
344
{
330
- if ( invokeResult != null )
331
- {
332
- success = true ;
333
- answer = APIUtils . FromAPIResult ( new Invocation ( ) { result = Base16 . Encode ( invokeResult ) } ) ;
334
- }
335
- else
345
+ answer = APIUtils . FromAPIResult ( new Error ( ) { message = $ "signTx: Invalid script data" } ) ;
346
+ }
347
+ else
348
+ {
349
+ InvokeScript ( script , id , ( invokeResult , invokeError ) =>
336
350
{
337
- answer = APIUtils . FromAPIResult ( new Error ( ) { message = invokeError } ) ;
338
- }
351
+ if ( invokeResult != null )
352
+ {
353
+ success = true ;
354
+ answer = APIUtils . FromAPIResult ( new Invocation ( ) { result = Base16 . Encode ( invokeResult ) } ) ;
355
+ }
356
+ else
357
+ {
358
+ answer = APIUtils . FromAPIResult ( new Error ( ) { message = invokeError } ) ;
359
+ }
339
360
340
- callback ( id , answer , success ) ;
341
- _isPendingRequest = false ;
342
- } ) ;
343
- return ;
361
+ callback ( id , answer , success ) ;
362
+ _isPendingRequest = false ;
363
+ } ) ;
364
+ return ;
365
+ }
344
366
}
345
367
else
346
368
{
@@ -360,23 +382,31 @@ public void Execute(string cmd, Action<int, DataNode, bool> callback)
360
382
{
361
383
var archiveHash = Hash . Parse ( args [ 1 ] ) ;
362
384
var blockIndex = int . Parse ( args [ 2 ] ) ;
363
- var bytes = Base16 . Decode ( args [ 3 ] ) ;
385
+ var bytes = Base16 . Decode ( args [ 3 ] , false ) ;
364
386
365
- WriteArchive ( archiveHash , blockIndex , bytes , ( result , error ) =>
387
+ if ( bytes == null )
366
388
{
367
- if ( result )
368
- {
369
- success = true ;
370
- answer = APIUtils . FromAPIResult ( new Transaction ( ) { hash = archiveHash . ToString ( ) } ) ;
371
- }
372
- else
389
+ answer = APIUtils . FromAPIResult ( new Error ( ) { message = $ "invokeScript: Invalid archive data"} ) ;
390
+ }
391
+ else
392
+ {
393
+ WriteArchive ( archiveHash , blockIndex , bytes , ( result , error ) =>
373
394
{
374
- answer = APIUtils . FromAPIResult ( new Error ( ) { message = error } ) ;
375
- }
395
+ if ( result )
396
+ {
397
+ success = true ;
398
+ answer = APIUtils . FromAPIResult ( new Transaction ( ) { hash = archiveHash . ToString ( ) } ) ;
399
+ }
400
+ else
401
+ {
402
+ answer = APIUtils . FromAPIResult ( new Error ( ) { message = error } ) ;
403
+ }
376
404
377
- callback ( id , answer , success ) ;
378
- _isPendingRequest = false ;
379
- } ) ;
405
+ callback ( id , answer , success ) ;
406
+ _isPendingRequest = false ;
407
+ } ) ;
408
+ }
409
+
380
410
return ;
381
411
}
382
412
else
0 commit comments