Browse Source

Fix some EPASA concepts

EPASA is returned as a JSON-RPC param at receivers instead of senders. Also will only return value when operation was made usign EPASA standard, (Deterministic)
PascalCoin 4 years ago
parent
commit
bf736816fb

+ 3 - 0
CHANGELOG.md

@@ -13,6 +13,9 @@
   - Added "ABSTRACTMEM_USE_CACHE_ON_LISTS","ABSTRACTMEM_CACHE_MAX_ACCOUNTS","ABSTRACTMEM_CACHE_MAX_PUBKEYS" in order to customize cache values
 - Improved performance when downloading Safebox (Fresh installation)
 - JSON-RPC changes:  
+  - Updated "Operation Object" return values:
+    - "receivers" : ARRAY
+      - "account_epasa" : (String) If operation was using valid E-PASA format, will return E-PASA format
   - Updated "findaccounts": 
     -New param "end" (integer, -1 for default): Will search from "start" to "end" (if "end"=-1 will search to the end)
   - New method "findblocks": Will search and return an array of "Block objects"

+ 2 - 0
src/core/UAccounts.pas

@@ -1914,7 +1914,9 @@ var
   LPublic, LRecipientKeyEncrypted, LSenderKeyEncrypted,
   LPasswordEncrypted, LAsciiFormatted, LHexFormatted, LBase58Formatted, LAddressedByName : Boolean;
 begin
+  AEPasa.Clear;
   LPayloadType := TEPasaComp.FromProtocolValue(APayloadType);
+  if LPayloadType.HasTrait(ptNonDeterministic) then Exit(False);
   LPublic := LPayloadType.HasTrait(ptPublic);
   LRecipientKeyEncrypted := LPayloadType.HasTrait(ptRecipientKeyEncrypted);
   LSenderKeyEncrypted := LPayloadType.HasTrait(ptSenderKeyEncrypted);

+ 4 - 3
src/core/UBlockChain.pas

@@ -139,7 +139,6 @@ Type
 
   TMultiOpSender = Record
     Account : Cardinal;
-    AccountEPASA : TEPasa;
     Amount : Int64;
     N_Operation : Cardinal;
     OpData : TMultiOpData; // Filled only when Operation is TOpData type
@@ -577,7 +576,7 @@ Type
 Const
   CT_TOperationPayload_NUL : TOperationPayload = (payload_type:0;payload_raw:Nil);
   CT_TOperationResume_NUL : TOperationResume = (valid:false;Block:0;NOpInsideBlock:-1;OpType:0;OpSubtype:0;time:0;AffectedAccount:0;SignerAccount:-1;n_operation:0;DestAccount:-1;SellerAccount:-1;newKey:(EC_OpenSSL_NID:0;x:Nil;y:Nil);OperationTxt:'';Amount:0;Fee:0;Balance:0;OriginalPayload:(payload_type:0;payload_raw:nil);PrintablePayload:'';OperationHash:Nil;OperationHash_OLD:Nil;errors:'';isMultiOperation:False;Senders:Nil;Receivers:Nil;changers:Nil);
-  CT_TMultiOpSender_NUL : TMultiOpSender =  (Account:0;(*AccountEPASA:TEPasa.Empty;*)Amount:0;N_Operation:0;Payload:(payload_type:0;payload_raw:Nil);Signature:(r:Nil;s:Nil));
+  CT_TMultiOpSender_NUL : TMultiOpSender =  (Account:0;Amount:0;N_Operation:0;Payload:(payload_type:0;payload_raw:Nil);Signature:(r:Nil;s:Nil));
   CT_TMultiOpReceiver_NUL : TMultiOpReceiver = (Account:0;Amount:0;Payload:(payload_type:0;payload_raw:Nil));
   CT_TMultiOpChangeInfo_NUL : TMultiOpChangeInfo = (Account:0;N_Operation:0;Changes_type:[];New_Accountkey:(EC_OpenSSL_NID:0;x:Nil;y:Nil);New_Name:Nil;New_Type:0;New_Data:Nil;Seller_Account:-1;Account_Price:-1;Locked_Until_Block:0;
     Hashed_secret:Nil;
@@ -3818,7 +3817,9 @@ begin
   l := FList.LockList;
   try
     if index<l.Count then Result := POperationResume(l[index])^
-    else Result := CT_TOperationResume_NUL;
+    else begin
+      Result := CT_TOperationResume_NUL;
+    end;
   finally
     FList.UnlockList;
   end;

+ 3 - 1
src/core/UEPasa.pas

@@ -390,6 +390,8 @@ var
   LPayloadContent: String;
 begin
   Result := string.Empty;
+  if (Not Account.HasValue) then Exit;
+  if PayloadType.HasTrait(ptNonDeterministic) then Exit;
   if (PayloadType.HasTrait(ptAddressedByName)) then begin
     Result := Result + TPascal64Encoding.Escape(AccountName);
   end else begin
@@ -494,7 +496,7 @@ var
   LActualAccountChecksum: Byte;
 begin
   AErrorCode := EPasaErrorCode.Success;
-  AEPasa := TEPasa.Empty;
+  AEPasa.Clear;
   if (string.IsNullOrEmpty(AEPasaText)) then begin
     AErrorCode := EPasaErrorCode.BadFormat;
     Exit(False);

+ 3 - 1
src/core/UOpTransaction.pas

@@ -1189,7 +1189,6 @@ begin
   SetLength(OperationResume.Senders,1);
   OperationResume.Senders[0] := CT_TMultiOpSender_NUL;
   OperationResume.Senders[0].Account:=FData.sender;
-  OperationResume.Senders[0].AccountEPASA := TAccountComp.DecodeEPASAPartial(FData.sender, FData.payload.payload_raw, FData.payload.payload_type, TEPasa.Empty);
   OperationResume.Senders[0].Amount:=Int64(FData.amount + FData.fee);
   OperationResume.Senders[0].N_Operation:=FData.n_operation;
   OperationResume.Senders[0].Payload:=FData.payload;
@@ -1206,10 +1205,12 @@ begin
     buy_account, transaction_with_auto_buy_account, transaction_with_auto_atomic_swap : begin
       SetLength(OperationResume.Receivers,2);
       OperationResume.Receivers[0] := CT_TMultiOpReceiver_NUL;
+      OperationResume.Receivers[0].AccountEPASA.Clear;
       OperationResume.Receivers[0].Account:=FData.target;
       OperationResume.Receivers[0].Amount:= (FData.amount - FData.AccountPrice);
       OperationResume.Receivers[0].Payload:=FData.payload;
       OperationResume.Receivers[1] := CT_TMultiOpReceiver_NUL;
+      OperationResume.Receivers[1].AccountEPASA.Clear;
       OperationResume.Receivers[1].Account:=FData.SellerAccount;
       OperationResume.Receivers[1].Amount:= FData.AccountPrice;
       OperationResume.Receivers[1].Payload:=FData.payload;
@@ -2651,6 +2652,7 @@ begin
   //
   SetLength(OperationResume.Receivers,1);
   OperationResume.Receivers[0] := CT_TMultiOpReceiver_NUL;
+  OperationResume.Receivers[0].AccountEPASA.Clear;
   OperationResume.Receivers[0].Account:=FData.account_target;
   OperationResume.Receivers[0].Amount:=FData.amount;
   OperationResume.Receivers[0].Payload:=FData.payload;

+ 5 - 3
src/core/URPC.pas

@@ -258,7 +258,6 @@ Begin
       LString := TCrypto.ToHexaString(OPR.Senders[i].Payload.payload_raw);
       auxObj := jsonArr.GetAsObject(jsonArr.Count);
       auxObj.GetAsVariant('account').Value := OPR.Senders[i].Account;
-      auxObj.GetAsVariant('account_epasa').Value := OPR.Senders[i].AccountEPASA.ToString();
       if (OPR.Senders[i].N_Operation>0) then auxObj.GetAsVariant('n_operation').Value := OPR.Senders[i].N_Operation;
       auxObj.GetAsVariant('amount').Value := TAccountComp.FormatMoneyDecimal(OPR.Senders[i].Amount * (-1));
       auxObj.GetAsVariant('amount_s').Value := TAccountComp.FormatMoney (OPR.Senders[i].Amount * (-1));
@@ -273,6 +272,7 @@ Begin
     for i:=Low(OPR.Receivers) to High(OPR.Receivers) do begin
       auxObj := jsonArr.GetAsObject(jsonArr.Count);
       auxObj.GetAsVariant('account').Value := OPR.Receivers[i].Account;
+      auxObj.GetAsVariant('account_epasa').Value := OPR.Receivers[i].AccountEPASA.ToString;
       auxObj.GetAsVariant('amount').Value :=  TAccountComp.FormatMoneyDecimal(OPR.Receivers[i].Amount);
       auxObj.GetAsVariant('amount_s').Value :=  TAccountComp.FormatMoney(OPR.Receivers[i].Amount);
       auxObj.GetAsVariant('payload').Value := TCrypto.ToHexaString(OPR.Receivers[i].Payload.payload_raw);
@@ -593,7 +593,6 @@ begin
     LStr := TCrypto.ToHexaString(multiOperation.Data.txSenders[i].Payload.payload_raw);
     auxObj := jsonArr.GetAsObject(jsonArr.Count);
     auxObj.GetAsVariant('account').Value := multiOperation.Data.txSenders[i].Account;
-    auxObj.GetAsVariant('account_epasa').Value := multiOperation.Data.txSenders[i].AccountEPASA.ToString();
     auxObj.GetAsVariant('n_operation').Value := multiOperation.Data.txSenders[i].N_Operation;
     auxObj.GetAsVariant('amount').Value := TAccountComp.FormatMoneyDecimal(multiOperation.Data.txSenders[i].Amount * (-1));
     auxObj.GetAsVariant('payload').Value := LStr;
@@ -1611,7 +1610,9 @@ function TRPCProcess.ProcessMethod(const method: String; params: TPCJSONObject;
         If TPCOperation.OperationToOperationResume(0,Op,True,Op.SignerAccount,OPR) then begin
           OPR.NOpInsideBlock := i;
           OPR.Balance := -1;
-        end else OPR := CT_TOperationResume_NUL;
+        end else begin
+          OPR := CT_TOperationResume_NUL;
+        end;
         FillOperationResumeToJSONObject(OPR,Obj);
       end;
       Result := true;
@@ -2551,6 +2552,7 @@ function TRPCProcess.ProcessMethod(const method: String; params: TPCJSONObject;
       jsonArr := params.GetAsArray('receivers');
       for i:=0 to jsonArr.Count-1 do begin
         receiver := CT_TMultiOpReceiver_NUL;
+        receiver.AccountEPASA.Clear;
         if NOT TryCaptureEPASA(jsonArr.GetAsObject(i), receiver.Account, ErrorNum, ErrorDesc) then
           Exit;
         receiver.Amount:= ToPascalCoins(jsonArr.GetAsObject(i).AsDouble('amount',0));

+ 4 - 1
src/core/UTxMultiOperation.pas

@@ -23,7 +23,7 @@ unit UTxMultiOperation;
 interface
 
 uses
-  Classes, SysUtils, UCrypto, UBlockChain, UAccounts, UBaseTypes,
+  Classes, SysUtils, UCrypto, UBlockChain, UAccounts, UBaseTypes, UEPasa,
   {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF},
   UPCDataTypes;
 
@@ -427,10 +427,13 @@ begin
     If (w>0) then begin
       for i:=0 to w-1 do begin
         txr := CT_TMultiOpReceiver_NUL;
+        txr.AccountEPASA.Clear;
         stream.Read(txr.Account,SizeOf(txr.Account));
         stream.Read(txr.Amount,SizeOf(txr.Amount));
         LoadOperationPayloadFromStream(stream,txr.Payload);
         //
+        txr.AccountEPASA:=TAccountComp.DecodeEPASAPartial(txr.Account,txr.Payload.payload_raw,txr.Payload.payload_type,TEPasa.Empty);
+        //
         txreceivers[i] := txr;
       end;
     end;