Browse Source

change on "multioperationaddoperation" call

Allow automatic n_operation value on "multioperationaddoperation"
JSON-RPC call
PascalCoin 7 years ago
parent
commit
9585d28054
2 changed files with 21 additions and 9 deletions
  1. 4 3
      README.md
  2. 17 6
      src/core/URPC.pas

+ 4 - 3
README.md

@@ -119,12 +119,13 @@ Also, consider a donation at PascalCoin development account: "0-10"
 	  - "enc_pubkey" : HESATRING with the public key that used to sign "digest" data
 	  - "enc_pubkey" : HESATRING with the public key that used to sign "digest" data
 	  - "signature" : HEXASTRING with signature
 	  - "signature" : HEXASTRING with signature
   - New method "multioperationaddoperation": Adds operations to a multioperation (or creates a new multioperation and adds new operations)
   - New method "multioperationaddoperation": Adds operations to a multioperation (or creates a new multioperation and adds new operations)
-    This method does not work with current Safebox state, so can be used offline or on COLD wallets
+    This method does not need current Safebox state, so can be used offline or on COLD wallets when all info is provided
     - Params:
     - Params:
       - "rawoperations" : HEXASTRING (optional) with previous multioperation. If is valid and contains a single  multiopertion will add operations to this one, otherwise will generate a NEW MULTIOPERATION
       - "rawoperations" : HEXASTRING (optional) with previous multioperation. If is valid and contains a single  multiopertion will add operations to this one, otherwise will generate a NEW MULTIOPERATION
+	  - "auto_n_operation" : Boolean - Will fill n_operation (if not provided). Only valid if wallet is ONLINE (no cold wallets)
       - "senders" : ARRAY of objects that will be Senders of the multioperation
       - "senders" : ARRAY of objects that will be Senders of the multioperation
         - "account" : Integer
         - "account" : Integer
-        - "n_operation" : Integer - Must provide a valid n_operation+1 value
+        - "n_operation" : Integer (optional) - if not provided, will use current safebox n_operation+1 value (on online wallets)
         - "amount" : PASCURRENCY in positive format
         - "amount" : PASCURRENCY in positive format
         - "payload" : HEXASTRING
         - "payload" : HEXASTRING
       - "receivers" : ARRAY of objects that will be Receivers of the multioperation
       - "receivers" : ARRAY of objects that will be Receivers of the multioperation
@@ -133,7 +134,7 @@ Also, consider a donation at PascalCoin development account: "0-10"
         - "payload" : HEXASTRING
         - "payload" : HEXASTRING
       - "changesinfo" : ARRAY of objects that will be accounts executing a changing info
       - "changesinfo" : ARRAY of objects that will be accounts executing a changing info
         - "account" : Integer
         - "account" : Integer
-        - "n_operation" : Integer - Must provide a valid n_operation+1 value
+        - "n_operation" : Integer (optional) - if not provided, will use current safebox n_operation+1 value (on online wallets)
         - "new_b58_pubkey"/"new_enc_pubkey": (optional) If provided will update Public key of "account"
         - "new_b58_pubkey"/"new_enc_pubkey": (optional) If provided will update Public key of "account"
         - "new_name" : STRING (optional) If provided will change account name
         - "new_name" : STRING (optional) If provided will change account name
         - "new_type" : Integer (optional) If provided will change account type
         - "new_type" : Integer (optional) If provided will change account type

+ 17 - 6
src/core/URPC.pas

@@ -2269,6 +2269,13 @@ function TRPCProcess.ProcessMethod(const method: String; params: TPCJSONObject;
   end;
   end;
 
 
   function MultiOperationAddOperation(Const HexaStringOperationsHashTree : TRawBytes; params : TPCJSONObject) : boolean;
   function MultiOperationAddOperation(Const HexaStringOperationsHashTree : TRawBytes; params : TPCJSONObject) : boolean;
+    Function Capture_Current_Account(const nAccount : Int64) : TAccount;
+    Begin
+      Result := CT_Account_NUL;
+      if (nAccount<0) Or (nAccount>=FNode.Bank.AccountsCount) then Exit;
+      Result := FNode.Operations.SafeBoxTransaction.Account( nAccount );
+    end;
+
   var errors : AnsiString;
   var errors : AnsiString;
     OperationsHashTree : TOperationsHashTree;
     OperationsHashTree : TOperationsHashTree;
     jsonArr : TPCJSONArray;
     jsonArr : TPCJSONArray;
@@ -2319,6 +2326,9 @@ function TRPCProcess.ProcessMethod(const method: String; params: TPCJSONObject;
         sender.Account := j;
         sender.Account := j;
         sender.Amount:= ToPascalCoins(jsonArr.GetAsObject(i).AsDouble('amount',0));
         sender.Amount:= ToPascalCoins(jsonArr.GetAsObject(i).AsDouble('amount',0));
         sender.N_Operation:=jsonArr.GetAsObject(i).AsInteger('n_operation',0);
         sender.N_Operation:=jsonArr.GetAsObject(i).AsInteger('n_operation',0);
+        // Update N_Operation with valid info
+        if (sender.N_Operation<=0) then sender.N_Operation:=Capture_Current_Account(sender.Account).n_operation+1;
+
         sender.Payload:=TCrypto.HexaToRaw(jsonArr.GetAsObject(i).AsString('payload',''));
         sender.Payload:=TCrypto.HexaToRaw(jsonArr.GetAsObject(i).AsString('payload',''));
         if Not mop.AddTxSender(sender) then begin
         if Not mop.AddTxSender(sender) then begin
           ErrorNum := CT_RPC_ErrNum_InvalidData;
           ErrorNum := CT_RPC_ErrNum_InvalidData;
@@ -2357,6 +2367,9 @@ function TRPCProcess.ProcessMethod(const method: String; params: TPCJSONObject;
         end;
         end;
         changeinfo.Account := j;
         changeinfo.Account := j;
         changeinfo.N_Operation:=jsonArr.GetAsObject(i).AsInteger('n_operation',0);
         changeinfo.N_Operation:=jsonArr.GetAsObject(i).AsInteger('n_operation',0);
+        // Update N_Operation with valid info
+        if (changeinfo.N_Operation<=0) then changeinfo.N_Operation:=Capture_Current_Account(changeinfo.Account).n_operation+1;
+
         if (jsonArr.GetAsObject(i).IndexOfName('new_b58_pubkey')>=0) or (jsonArr.GetAsObject(i).IndexOfName('new_enc_pubkey')>=0) then begin
         if (jsonArr.GetAsObject(i).IndexOfName('new_b58_pubkey')>=0) or (jsonArr.GetAsObject(i).IndexOfName('new_enc_pubkey')>=0) then begin
           changeinfo.Changes_type:=changeinfo.Changes_type + [public_key];
           changeinfo.Changes_type:=changeinfo.Changes_type + [public_key];
           If Not CapturePubKeyExt(jsonArr.GetAsObject(i),'new_',changeinfo.New_Accountkey,ErrorDesc) then begin
           If Not CapturePubKeyExt(jsonArr.GetAsObject(i),'new_',changeinfo.New_Accountkey,ErrorDesc) then begin
@@ -3161,24 +3174,22 @@ begin
     Result := ChangeAccountInfo(params);
     Result := ChangeAccountInfo(params);
   end else if (method='signchangeaccountinfo') then begin
   end else if (method='signchangeaccountinfo') then begin
     Result := SignChangeAccountInfoColdWallet(params.AsString('rawoperations',''),params);
     Result := SignChangeAccountInfoColdWallet(params.AsString('rawoperations',''),params);
-  // V3 new  XXXXXXXXXXXXXXXX
+  // V3 new calls
   end else if (method='signmessage') then begin
   end else if (method='signmessage') then begin
     params.DeleteName('signature');
     params.DeleteName('signature');
     Result := DoSignOrVerifyMessage(params);
     Result := DoSignOrVerifyMessage(params);
   end else if (method='verifysign') then begin
   end else if (method='verifysign') then begin
     if (params.IndexOfName('signature')<0) then params.GetAsVariant('signature').Value:=''; // Init signature value to force verify
     if (params.IndexOfName('signature')<0) then params.GetAsVariant('signature').Value:=''; // Init signature value to force verify
     Result := DoSignOrVerifyMessage(params);
     Result := DoSignOrVerifyMessage(params);
-  // V3 Multioperation XXXXXXXXXXXXXXX
+  end else if (method='operationsdelete') then begin
+    Result := RawOperations_Delete(params.AsString('rawoperations',''),params.AsInteger('index',-1));
+  // V3 Multioperation
   end else if (method='multioperationaddoperation') then begin
   end else if (method='multioperationaddoperation') then begin
     Result := MultiOperationAddOperation(params.AsString('rawoperations',''),params);
     Result := MultiOperationAddOperation(params.AsString('rawoperations',''),params);
   end else if (method='multioperationsignoffline') then begin
   end else if (method='multioperationsignoffline') then begin
     Result := MultiOperationSignCold(params.AsString('rawoperations',''),params);
     Result := MultiOperationSignCold(params.AsString('rawoperations',''),params);
   end else if (method='multioperationsignonline') then begin
   end else if (method='multioperationsignonline') then begin
     Result := MultiOperationSignOnline(params.AsString('rawoperations',''));
     Result := MultiOperationSignOnline(params.AsString('rawoperations',''));
-  // XXXXXXXXXXX
-  end else if (method='operationsdelete') then begin
-    // Will remove an operation from rawoperations
-    Result := RawOperations_Delete(params.AsString('rawoperations',''),params.AsInteger('index',-1));
   //
   //
   end else if (method='operationsinfo') then begin
   end else if (method='operationsinfo') then begin
     Result := OperationsInfo(params.AsString('rawoperations',''),GetResultArray);
     Result := OperationsInfo(params.AsString('rawoperations',''),GetResultArray);