Browse Source

README, JSON-RPC and GUI update with PIP-0032

PascalCoin 6 years ago
parent
commit
6bdc3e830f
4 changed files with 66 additions and 2 deletions
  1. 11 0
      README.md
  2. 30 1
      src/core/URPC.pas
  3. 1 1
      src/gui-classic/UFRMOperation.pas
  4. 24 0
      src/gui-classic/UFRMWallet.pas

+ 11 - 0
README.md

@@ -37,11 +37,13 @@ Also, consider a donation at PascalCoin development account: "0-10"
 ### Current Build (Pending release date)
 - Upgrade to Protocol 5 (Hard fork)
 - Implementation of PIP-0032 (Atomic Swaps) -> https://github.com/PascalCoin/PascalCoin/blob/master/PIP/PIP-0032.md
+  - Atomic Swaps can be executed ONLY during the locking period specified
 - Implementation of PIP-0030 (Safebox root) -> https://github.com/PascalCoin/PascalCoin/blob/master/PIP/PIP-0030.md
 - Implementation of PIP-0029 (Account Seals) -> https://github.com/PascalCoin/PascalCoin/blob/master/PIP/PIP-0029.md
 - New digest hash value for OP_DATA ( PIP-0016 ) on Protocol 5
 - Hardcoded RandomHash digest/hash values for quick speed safebox check on fresh installation
 - JSON-RPC changes:
+  - Updated ""
   - Updated "listaccountforsale" call to allow ATOMIC SWAPS (PIP-0032)
     - Added "type" to discrimine between kind of listing. Available values are:
       - "public_sale"
@@ -50,6 +52,15 @@ Also, consider a donation at PascalCoin development account: "0-10"
       - "atomic_coin_swap": Need to provide a valid "enc_hash_lock"
       - If no "type" is defined, will automatically select between "public_sale" or "private_sale"
     - Added "enc_hash_lock" (HEXASTRING) that must be exactly a 32 bytes value (stored as 64 bytes because is HexaString)
+  - Updated "Account Object" return values:
+    - "state": Can return "normal", "listed", "account_swap", "coin_swap"
+    - "hashed_secret" : (HEXASTRING) will contain the SHA256( SECRET ) value that must match Payload received data for Atomic Swaps (only when "state" in "account_swap" or "coin_swap")
+	- "amount_to_swap" : (PASCURRENCY) amount that will be transferred to counterparty account on ATOMIC COIN SWAP ("receiver_swap_account")
+	- "receiver_swap_account": (Integer) Counterpaty account that will receive "amount_to_swap" on ATOMIC COIN SWAP
+  - Updated "Operation Object" return values:
+    - "changers" : ARRAY
+      - "new_data" : (HEXASTRING) : If "data" is changed on "account"
+      - "changes" : (String) Description of changes type made
 TODO  
 - TODO: RPC calls for PIP-0029
 - TODO Implement Seal calculation

+ 30 - 1
src/core/URPC.pas

@@ -178,6 +178,8 @@ end;
 
 class procedure TPascalCoinJSONComp.FillOperationObject(const OPR: TOperationResume; currentNodeBlocksCount : Cardinal; jsonObject: TPCJSONObject);
 Var i : Integer;
+  LOpChangeAccountInfoType : TOpChangeAccountInfoType;
+  LString : String;
   jsonArr : TPCJSONArray;
   auxObj : TPCJSONObject;
 
@@ -251,6 +253,9 @@ Begin
       If account_type in OPR.Changers[i].Changes_type then begin
         auxObj.GetAsVariant('new_type').Value := OPR.Changers[i].New_Type;
       end;
+      If account_data in OPR.Changers[i].Changes_type then begin
+        auxObj.GetAsVariant('new_data').Value := OPR.Changers[i].New_Data.ToHexaString;
+      end;
       if (list_for_public_sale in OPR.Changers[i].Changes_type)
         Or (list_for_private_sale in OPR.Changers[i].Changes_type) then begin
         auxObj.GetAsVariant('seller_account').Value := OPR.Changers[i].Seller_Account;
@@ -268,6 +273,16 @@ Begin
       if (OPR.OpType = CT_Op_Data) then begin
         FillDataObject(auxObj, OPR.Changers[i].Data);
       end;
+      LString := '';
+      for LOpChangeAccountInfoType := Low(LOpChangeAccountInfoType) to High(LOpChangeAccountInfoType) do begin
+        if (LOpChangeAccountInfoType in OPR.Changers[i].Changes_type) then begin
+          if LString<>'' then LString := LString + ',';
+          LString := LString + CT_TOpChangeAccountInfoType_Txt[LOpChangeAccountInfoType];
+        end;
+      end;
+      if LString<>'' then begin
+        auxObj.GetAsVariant('changes').Value := LString;
+      end;
     end;
   jsonObject.GetAsVariant('optxt').Value:=OPR.OperationTxt;
   jsonObject.GetAsVariant('fee').Value:=TAccountComp.FormatMoneyDecimal(OPR.Fee);
@@ -317,7 +332,21 @@ Begin
       if not (account.accountInfo.new_publicKey.EC_OpenSSL_NID<>0) then begin
         jsonObj.GetAsVariant('new_enc_pubkey').Value := TCrypto.ToHexaString(TAccountComp.AccountKey2RawString(account.accountInfo.new_publicKey));
       end;
-    end
+    end;
+    as_ForAtomicAccountSwap : begin
+      jsonObj.GetAsVariant('state').Value:='account_swap';
+      jsonObj.GetAsVariant('locked_until_block').Value:=account.accountInfo.locked_until_block;
+      jsonObj.GetAsVariant('new_enc_pubkey').Value := TCrypto.ToHexaString(TAccountComp.AccountKey2RawString(account.accountInfo.new_publicKey));
+      jsonObj.GetAsVariant('hashed_secret').Value := account.account_data.ToHexaString;
+    end;
+    as_ForAtomicCoinSwap : begin
+      jsonObj.GetAsVariant('state').Value:='coin_swap';
+      jsonObj.GetAsVariant('locked_until_block').Value:=account.accountInfo.locked_until_block;
+      jsonObj.GetAsVariant('amount_to_swap').Value:=TAccountComp.FormatMoneyDecimal(account.accountInfo.price);
+      jsonObj.GetAsVariant('amount_to_swap_s').Value:=TAccountComp.FormatMoney(account.accountInfo.price);
+      jsonObj.GetAsVariant('receiver_swap_account').Value:=account.accountInfo.account_to_pay;
+      jsonObj.GetAsVariant('hashed_secret').Value := account.account_data.ToHexaString;
+    end;
   else raise Exception.Create('ERROR DEV 20170425-1');
   end;
   jsonObj.GetAsVariant('name').Value := account.name.ToPrintable;

+ 1 - 1
src/gui-classic/UFRMOperation.pas

@@ -309,7 +309,7 @@ loop_start:
             destAccount.account,_newOwnerPublicKey,_lockedUntil,LKey.PrivateKey, LHashLock, FEncodedPayload);
         end  else if (rbListAccountForCoinSwap.Checked) then begin
           op := TOpListAccountForSaleOrSwap.CreateListAccountForSaleOrSwap(FNode.Bank.SafeBox.CurrentProtocol, as_ForAtomicCoinSwap, signerAccount.account,signerAccount.n_operation+1+iAcc, account.account,_salePrice,_fee,
-            destAccount.account,_newOwnerPublicKey,_lockedUntil,LKey.PrivateKey, LHashLock, FEncodedPayload);
+            destAccount.account,CT_TECDSA_Public_Nul,_lockedUntil,LKey.PrivateKey, LHashLock, FEncodedPayload);
         end else raise Exception.Create('Select Sale type');
         {%endregion}
       end else if (PageControlOpType.ActivePage = tsDelistAccount) then begin

+ 24 - 0
src/gui-classic/UFRMWallet.pas

@@ -899,6 +899,10 @@ begin
   Strings.Add(Format('Updated on block: %d  (%d blocks ago)',[account.updated_block,FNode.Bank.BlocksCount-account.updated_block]));
   Strings.Add(Format('Public key type: %s',[TAccountComp.GetECInfoTxt(account.accountInfo.accountKey.EC_OpenSSL_NID)]));
   Strings.Add(Format('Base58 Public key: %s',[TAccountComp.AccountPublicKeyExport(account.accountInfo.accountKey)]));
+  if Length(account.account_data)>0 then
+    Strings.Add(Format('Account Data: %s',[account.account_data.ToHexaString]))
+  else Strings.Add(Format('Account Data: (No data)',[]));
+  Strings.Add(Format('Account Seal: %s',[account.account_seal.ToHexaString]));
   if TAccountComp.IsAccountForSale(account.accountInfo) then begin
     Strings.Add('');
     Strings.Add('** Account is for sale: **');
@@ -917,7 +921,27 @@ begin
           [account.accountInfo.locked_until_block,FNode.Bank.BlocksCount]));
       end;
     end;
+  end else if TAccountComp.IsAccountForSwap(account.accountInfo) then begin
+    Strings.Add('');
+    if TAccountComp.IsAccountForAccountSwap(account.accountInfo) then begin
+      Strings.Add('** Account is for Atomic Account Swap: **');
+      Strings.Add(Format('New Base58 Public key: %s',[TAccountComp.AccountPublicKeyExport(account.accountInfo.new_publicKey)]));
+    end else if TAccountComp.IsAccountForCoinSwap(account.accountInfo) then begin
+      Strings.Add('** Account is for Atomic Coin Swap: **');
+      Strings.Add(Format('Amount to swap: %s',[TAccountComp.FormatMoney(account.accountInfo.price)]));
+      Strings.Add(Format('Counterparty account: %s',[TAccountComp.AccountNumberToAccountTxtNumber(account.accountInfo.account_to_pay)]));
+    end;
+    Strings.Add(Format('Public secret to find: %s',[account.account_data.ToHexaString]));
+    Strings.Add('');
+    if TAccountComp.IsAccountLocked(account.accountInfo,FNode.Bank.BlocksCount) then begin
+      Strings.Add(Format('SWAP IS SECURE UNTIL BLOCK %d (current %d, remains %d)',
+          [account.accountInfo.locked_until_block,FNode.Bank.BlocksCount,account.accountInfo.locked_until_block-FNode.Bank.BlocksCount]));
+    end else begin
+        Strings.Add(Format('SWAP IS NOT SECURE (Expired on block %d, current %d)',
+          [account.accountInfo.locked_until_block,FNode.Bank.BlocksCount]));
+    end;
   end;
+
 end;
 
 procedure TFRMWallet.FillOperationInformation(const Strings: TStrings;