Browse Source

OperationAmountByAccount

Implementation of OperationAmountByAccount in each TPCOperation
PascalCoin 7 years ago
parent
commit
76a2cacc69
1 changed files with 42 additions and 0 deletions
  1. 42 0
      src/core/UOpTransaction.pas

+ 42 - 0
src/core/UOpTransaction.pas

@@ -89,6 +89,7 @@ Type
     function DestinationAccount : Int64; override;
     function DestinationAccount : Int64; override;
     function SellerAccount : Int64; override;
     function SellerAccount : Int64; override;
     function N_Operation : Cardinal; override;
     function N_Operation : Cardinal; override;
+    function OperationAmountByAccount(account : Cardinal) : Int64; override;
     Property Data : TOpTransactionData read FData;
     Property Data : TOpTransactionData read FData;
 
 
     Constructor CreateTransaction(sender, n_operation, target: Cardinal; key: TECPrivateKey; amount, fee: UInt64; payload: TRawBytes);
     Constructor CreateTransaction(sender, n_operation, target: Cardinal; key: TECPrivateKey; amount, fee: UInt64; payload: TRawBytes);
@@ -119,6 +120,7 @@ Type
     function DestinationAccount : Int64; override;
     function DestinationAccount : Int64; override;
     function N_Operation : Cardinal; override;
     function N_Operation : Cardinal; override;
     procedure AffectedAccounts(list : TList); override;
     procedure AffectedAccounts(list : TList); override;
+    function OperationAmountByAccount(account : Cardinal) : Int64; override;
     Constructor Create(account_signer, n_operation, account_target: Cardinal; key:TECPrivateKey; new_account_key : TAccountKey; fee: UInt64; payload: TRawBytes);
     Constructor Create(account_signer, n_operation, account_target: Cardinal; key:TECPrivateKey; new_account_key : TAccountKey; fee: UInt64; payload: TRawBytes);
     Property Data : TOpChangeKeyData read FData;
     Property Data : TOpChangeKeyData read FData;
     Function toString : String; Override;
     Function toString : String; Override;
@@ -152,6 +154,7 @@ Type
     function OperationPayload : TRawBytes; override;
     function OperationPayload : TRawBytes; override;
     function SignerAccount : Cardinal; override;
     function SignerAccount : Cardinal; override;
     function N_Operation : Cardinal; override;
     function N_Operation : Cardinal; override;
+    function OperationAmountByAccount(account : Cardinal) : Int64; override;
     procedure AffectedAccounts(list : TList); override;
     procedure AffectedAccounts(list : TList); override;
     Constructor Create(account_number, n_operation: Cardinal; fee: UInt64);
     Constructor Create(account_number, n_operation: Cardinal; fee: UInt64);
     Property Data : TOpRecoverFoundsData read FData;
     Property Data : TOpRecoverFoundsData read FData;
@@ -224,6 +227,7 @@ Type
     function SellerAccount : Int64; override;
     function SellerAccount : Int64; override;
     function N_Operation : Cardinal; override;
     function N_Operation : Cardinal; override;
     procedure AffectedAccounts(list : TList); override;
     procedure AffectedAccounts(list : TList); override;
+    function OperationAmountByAccount(account : Cardinal) : Int64; override;
     Property Data : TOpListAccountData read FData;
     Property Data : TOpListAccountData read FData;
     Function toString : String; Override;
     Function toString : String; Override;
   End;
   End;
@@ -276,6 +280,7 @@ Type
     function DestinationAccount : Int64; override;
     function DestinationAccount : Int64; override;
     function N_Operation : Cardinal; override;
     function N_Operation : Cardinal; override;
     procedure AffectedAccounts(list : TList); override;
     procedure AffectedAccounts(list : TList); override;
+    function OperationAmountByAccount(account : Cardinal) : Int64; override;
     Constructor CreateChangeAccountInfo(account_signer, n_operation, account_target: Cardinal; key:TECPrivateKey;
     Constructor CreateChangeAccountInfo(account_signer, n_operation, account_target: Cardinal; key:TECPrivateKey;
       change_key : Boolean; const new_account_key : TAccountKey;
       change_key : Boolean; const new_account_key : TAccountKey;
       change_name: Boolean; const new_name : TRawBytes;
       change_name: Boolean; const new_name : TRawBytes;
@@ -595,6 +600,12 @@ begin
   if (FData.account_target<>FData.account_signer) then list.Add(TObject(FData.account_target));
   if (FData.account_target<>FData.account_signer) then list.Add(TObject(FData.account_target));
 end;
 end;
 
 
+function TOpChangeAccountInfo.OperationAmountByAccount(account: Cardinal): Int64;
+begin
+  if (FData.account_signer = account) then Result := Int64(FData.fee)*(-1)
+  else Result := 0;
+end;
+
 constructor TOpChangeAccountInfo.CreateChangeAccountInfo(account_signer, n_operation,
 constructor TOpChangeAccountInfo.CreateChangeAccountInfo(account_signer, n_operation,
   account_target: Cardinal; key: TECPrivateKey; change_key: Boolean;
   account_target: Cardinal; key: TECPrivateKey; change_key: Boolean;
   const new_account_key: TAccountKey; change_name: Boolean;
   const new_account_key: TAccountKey; change_name: Boolean;
@@ -1080,6 +1091,19 @@ begin
   Result := FData.n_operation;
   Result := FData.n_operation;
 end;
 end;
 
 
+function TOpTransaction.OperationAmountByAccount(account: Cardinal): Int64;
+begin
+  Result := 0;
+  If (FData.sender = account) then inc(Result, Int64(FData.amount+FData.fee) * (-1));
+  If (FData.target = account) then begin
+    if (FData.opTransactionStyle in [buy_account,transaction_with_auto_buy_account]) then inc(Result, FData.amount - FData.AccountPrice)
+    else inc(Result,FData.amount);
+  end;
+  If ((FData.SellerAccount = account) And (FData.opTransactionStyle in [buy_account,transaction_with_auto_buy_account] )) then begin
+    inc(Result, FData.AccountPrice)
+  end;
+end;
+
 function TOpTransaction.toString: String;
 function TOpTransaction.toString: String;
 begin
 begin
   case FData.opTransactionStyle of
   case FData.opTransactionStyle of
@@ -1112,6 +1136,12 @@ begin
   if (FData.account_target<>FData.account_signer) then list.Add(TObject(FData.account_target));
   if (FData.account_target<>FData.account_signer) then list.Add(TObject(FData.account_target));
 end;
 end;
 
 
+function TOpChangeKey.OperationAmountByAccount(account: Cardinal): Int64;
+begin
+  if (FData.account_signer = account) then Result := Int64(FData.fee)*(-1)
+  else Result := 0;
+end;
+
 constructor TOpChangeKey.Create(account_signer, n_operation, account_target: Cardinal; key:TECPrivateKey; new_account_key : TAccountKey; fee: UInt64; payload: TRawBytes);
 constructor TOpChangeKey.Create(account_signer, n_operation, account_target: Cardinal; key:TECPrivateKey; new_account_key : TAccountKey; fee: UInt64; payload: TRawBytes);
 begin
 begin
   inherited Create;
   inherited Create;
@@ -1573,6 +1603,12 @@ begin
   Result := FData.n_operation;
   Result := FData.n_operation;
 end;
 end;
 
 
+function TOpRecoverFounds.OperationAmountByAccount(account: Cardinal): Int64;
+begin
+  if (FData.account = account) then Result := Int64(FData.fee)*(-1)
+  else Result := 0;
+end;
+
 function TOpRecoverFounds.toString: String;
 function TOpRecoverFounds.toString: String;
 begin
 begin
   Result := Format('Recover founds of account %s fee:%s (n_op:%d)',[
   Result := Format('Recover founds of account %s fee:%s (n_op:%d)',[
@@ -1589,6 +1625,12 @@ begin
     list.Add(TObject(FData.account_target));
     list.Add(TObject(FData.account_target));
 end;
 end;
 
 
+function TOpListAccount.OperationAmountByAccount(account: Cardinal): Int64;
+begin
+  if (FData.account_signer = account) then Result := Int64(FData.fee)*(-1)
+  else Result := 0;
+end;
+
 function TOpListAccount.DoOperation(AccountPreviousUpdatedBlock : TAccountPreviousBlockInfo; AccountTransaction : TPCSafeBoxTransaction; var errors : AnsiString) : Boolean;
 function TOpListAccount.DoOperation(AccountPreviousUpdatedBlock : TAccountPreviousBlockInfo; AccountTransaction : TPCSafeBoxTransaction; var errors : AnsiString) : Boolean;
 Var account_signer, account_target : TAccount;
 Var account_signer, account_target : TAccount;
 begin
 begin