Browse Source

Core: include operation data in object model

Herman Schoenfeld 6 years ago
parent
commit
cc51c9b9ec
3 changed files with 38 additions and 0 deletions
  1. 9 0
      src/core/UBlockChain.pas
  2. 10 0
      src/core/UOpTransaction.pas
  3. 19 0
      src/core/URPC.pas

+ 9 - 0
src/core/UBlockChain.pas

@@ -116,10 +116,17 @@ Type
   TOpChangeAccountInfoTypes = Set of TOpChangeAccountInfoType;
   TOpChangeAccountInfoTypes = Set of TOpChangeAccountInfoType;
 
 
   // MultiOp... will allow a MultiOperation
   // MultiOp... will allow a MultiOperation
+  TMultiOpData = record
+    ID : TGUID;
+    Sequence : UInt16;
+    &Type : UInt16;
+  end;
+
   TMultiOpSender = Record
   TMultiOpSender = Record
     Account : Cardinal;
     Account : Cardinal;
     Amount : Int64;
     Amount : Int64;
     N_Operation : Cardinal;
     N_Operation : Cardinal;
+    Data : TMultiOpData;
     Payload : TRawBytes;
     Payload : TRawBytes;
     Signature : TECDSA_SIG;
     Signature : TECDSA_SIG;
   end;
   end;
@@ -127,6 +134,7 @@ Type
   TMultiOpReceiver = Record
   TMultiOpReceiver = Record
     Account : Cardinal;
     Account : Cardinal;
     Amount : Int64;
     Amount : Int64;
+    Data : TMultiOpData;
     Payload : TRawBytes;
     Payload : TRawBytes;
   end;
   end;
   TMultiOpReceivers = Array of TMultiOpReceiver;
   TMultiOpReceivers = Array of TMultiOpReceiver;
@@ -140,6 +148,7 @@ Type
     Seller_Account : Int64;
     Seller_Account : Int64;
     Account_Price : Int64;
     Account_Price : Int64;
     Locked_Until_Block : Cardinal;
     Locked_Until_Block : Cardinal;
+    Data : TMultiOpData;
     Fee: Int64;
     Fee: Int64;
     Signature: TECDSA_SIG;
     Signature: TECDSA_SIG;
   end;
   end;

+ 10 - 0
src/core/UOpTransaction.pas

@@ -2230,6 +2230,9 @@ begin
     OperationResume.Senders[0].N_Operation:=FData.n_operation;
     OperationResume.Senders[0].N_Operation:=FData.n_operation;
     OperationResume.Senders[0].Signature:=FData.sign;
     OperationResume.Senders[0].Signature:=FData.sign;
     OperationResume.Senders[0].Amount:=Int64(FData.amount + FData.fee)*(-1);
     OperationResume.Senders[0].Amount:=Int64(FData.amount + FData.fee)*(-1);
+    OperationResume.Senders[0].Data.ID := StringToGUID('{00000000-0000-0000-0000-000000000000}'); // NOTE: ID missing in V4, added to V5
+    OperationResume.Senders[0].Data.Sequence := FData.dataSequence;
+    OperationResume.Senders[0].Data.&Type := FData.dataType;
   end else begin
   end else begin
     OperationResume.Senders[0].Amount:=Int64(FData.amount)*(-1);
     OperationResume.Senders[0].Amount:=Int64(FData.amount)*(-1);
     SetLength(OperationResume.Changers,1);
     SetLength(OperationResume.Changers,1);
@@ -2238,6 +2241,9 @@ begin
     OperationResume.Changers[0].Fee:=FData.fee;
     OperationResume.Changers[0].Fee:=FData.fee;
     OperationResume.Changers[0].N_Operation:=FData.n_operation;
     OperationResume.Changers[0].N_Operation:=FData.n_operation;
     OperationResume.Changers[0].Signature:=FData.sign;
     OperationResume.Changers[0].Signature:=FData.sign;
+    OperationResume.Senders[0].Data.ID := StringToGUID('{00000000-0000-0000-0000-000000000000}'); // NOTE: ID missing in V4, added to V5
+    OperationResume.Changers[0].Data.Sequence := FData.dataSequence;
+    OperationResume.Changers[0].Data.&Type := FData.dataType;
   end;
   end;
   //
   //
   SetLength(OperationResume.Receivers,1);
   SetLength(OperationResume.Receivers,1);
@@ -2245,6 +2251,10 @@ begin
   OperationResume.Receivers[0].Account:=FData.account_target;
   OperationResume.Receivers[0].Account:=FData.account_target;
   OperationResume.Receivers[0].Amount:=FData.amount;
   OperationResume.Receivers[0].Amount:=FData.amount;
   OperationResume.Receivers[0].Payload:=FData.payload;
   OperationResume.Receivers[0].Payload:=FData.payload;
+  OperationResume.Senders[0].Data.ID := StringToGUID('{00000000-0000-0000-0000-000000000000}'); // NOTE: ID missing in V4, added to V5
+  OperationResume.Receivers[0].Data.Sequence := FData.dataSequence;
+  OperationResume.Receivers[0].Data.&Type := FData.dataType;
+
   //
   //
   OperationResume.n_operation:=FData.n_operation;
   OperationResume.n_operation:=FData.n_operation;
   if (Affected_account_number = FData.account_signer) or (getInfoForAllAccounts) then begin
   if (Affected_account_number = FData.account_signer) or (getInfoForAllAccounts) then begin

+ 19 - 0
src/core/URPC.pas

@@ -184,6 +184,16 @@ class procedure TPascalCoinJSONComp.FillOperationObject(const OPR: TOperationRes
 Var i : Integer;
 Var i : Integer;
   jsonArr : TPCJSONArray;
   jsonArr : TPCJSONArray;
   auxObj : TPCJSONObject;
   auxObj : TPCJSONObject;
+
+  procedure FillDataObject(AParentObj : TPCJSONObject; const AData : TMultiOpData);
+  var LDataObj : TPCJSONObject;
+  begin
+    LDataObj := AParentObj.GetAsObject('data');
+    LDataObj.GetAsVariant('id').Value := AData.ID.ToString(True);
+    LDataObj.GetAsVariant('sequence').Value := AData.Sequence;
+    LDataObj.GetAsVariant('type').Value := AData.&Type;
+  end;
+
 Begin
 Begin
   if Not OPR.valid then begin
   if Not OPR.valid then begin
     jsonObject.GetAsVariant('valid').Value := OPR.valid;
     jsonObject.GetAsVariant('valid').Value := OPR.valid;
@@ -214,6 +224,9 @@ Begin
       if (OPR.Senders[i].N_Operation>0) then auxObj.GetAsVariant('n_operation').Value := OPR.Senders[i].N_Operation;
       if (OPR.Senders[i].N_Operation>0) then auxObj.GetAsVariant('n_operation').Value := OPR.Senders[i].N_Operation;
       auxObj.GetAsVariant('amount').Value := ToJSONCurrency(OPR.Senders[i].Amount * (-1));
       auxObj.GetAsVariant('amount').Value := ToJSONCurrency(OPR.Senders[i].Amount * (-1));
       auxObj.GetAsVariant('payload').Value := TCrypto.ToHexaString(OPR.Senders[i].Payload);
       auxObj.GetAsVariant('payload').Value := TCrypto.ToHexaString(OPR.Senders[i].Payload);
+      if (OPR.OpType = CT_Op_Data) then begin
+        FillDataObject(auxObj, OPR.Receivers[i].Data);
+      end;
     end;
     end;
     //
     //
     jsonArr := jsonObject.GetAsArray('receivers');
     jsonArr := jsonObject.GetAsArray('receivers');
@@ -222,6 +235,9 @@ Begin
       auxObj.GetAsVariant('account').Value := OPR.Receivers[i].Account;
       auxObj.GetAsVariant('account').Value := OPR.Receivers[i].Account;
       auxObj.GetAsVariant('amount').Value := ToJSONCurrency(OPR.Receivers[i].Amount);
       auxObj.GetAsVariant('amount').Value := ToJSONCurrency(OPR.Receivers[i].Amount);
       auxObj.GetAsVariant('payload').Value := TCrypto.ToHexaString(OPR.Receivers[i].Payload);
       auxObj.GetAsVariant('payload').Value := TCrypto.ToHexaString(OPR.Receivers[i].Payload);
+      if (OPR.OpType = CT_Op_Data) then begin
+        FillDataObject(auxObj, OPR.Receivers[i].Data);
+      end;
     end;
     end;
     jsonArr := jsonObject.GetAsArray('changers');
     jsonArr := jsonObject.GetAsArray('changers');
     for i:=Low(OPR.Changers) to High(OPR.Changers) do begin
     for i:=Low(OPR.Changers) to High(OPR.Changers) do begin
@@ -249,6 +265,9 @@ Begin
       if (OPR.Changers[i].Fee<>0) then begin
       if (OPR.Changers[i].Fee<>0) then begin
         auxObj.GetAsVariant('fee').Value := ToJSONCurrency(OPR.Changers[i].Fee * (-1));
         auxObj.GetAsVariant('fee').Value := ToJSONCurrency(OPR.Changers[i].Fee * (-1));
       end;
       end;
+      if (OPR.OpType = CT_Op_Data) then begin
+        FillDataObject(auxObj, OPR.Changers[i].Data);
+      end;
     end;
     end;
   jsonObject.GetAsVariant('optxt').Value:=OPR.OperationTxt;
   jsonObject.GetAsVariant('optxt').Value:=OPR.OperationTxt;
   jsonObject.GetAsVariant('fee').Value:=ToJSONCurrency(OPR.Fee);
   jsonObject.GetAsVariant('fee').Value:=ToJSONCurrency(OPR.Fee);