Skip to content

Commit

Permalink
Add effective received amount field (#4660)
Browse files Browse the repository at this point in the history
* Add effective received amount field

* Update API doc
  • Loading branch information
AurelienFT committed Mar 11, 2024
1 parent 7dd1ac2 commit df156f3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions massa-api-exports/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ pub struct Transfer {
pub to: Address,
/// The amount of the transfer
pub amount: Amount,
/// The effective amount received by the receiver
pub effective_amount_received: Amount,
/// If the transfer succeed or not
pub succeed: bool,
/// Fee
Expand Down
3 changes: 3 additions & 0 deletions massa-api/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl MassaRpcServer for API<Public> {
from: Address::from_str(&t_from).unwrap(),
to: Address::from_str(&t_to).unwrap(),
amount: Amount::from_raw(t_amount),
effective_amount_received: Amount::from_raw(t_amount),
context: TransferContext::ASC(i as u64),
succeed: true,
fee: Amount::from_raw(0),
Expand All @@ -178,6 +179,7 @@ impl MassaRpcServer for API<Public> {
from: Address::from_str(&t_from).unwrap(),
to: Address::from_str(&t_to).unwrap(),
amount: Amount::from_raw(t_amount),
effective_amount_received: Amount::from_raw(t_amount),
context: TransferContext::Operation(op_id),
succeed: true,
fee: Amount::from_raw(0),
Expand All @@ -197,6 +199,7 @@ impl MassaRpcServer for API<Public> {
from: t.from,
to: t.to,
amount: t.amount,
effective_amount_received: t.effective_received_amount,
context: TransferContext::Operation(t.op_id),
succeed: t.succeed,
fee: t.fee,
Expand Down
2 changes: 2 additions & 0 deletions massa-execution-exports/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ pub struct Transfer {
pub to: Address,
/// Amount
pub amount: Amount,
/// Effective received amount
pub effective_received_amount: Amount,
/// operation id
pub op_id: OperationId,
/// success or not
Expand Down
24 changes: 24 additions & 0 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,10 +1270,33 @@ impl ExecutionState {
recipient_address,
amount,
} => {
let receiver_balance = {
let context = context_guard!(self);
context.get_balance(recipient_address).unwrap_or_default()
};
let mut effective_received_amount = *amount;
if receiver_balance
== amount
.checked_sub(
self.config
.storage_costs_constants
.ledger_entry_base_cost,
)
.unwrap_or_default()
{
effective_received_amount = amount
.checked_sub(
self.config
.storage_costs_constants
.ledger_entry_base_cost,
)
.unwrap_or_default();
}
transfers.push(Transfer {
from: operation.content_creator_address,
to: *recipient_address,
amount: *amount,
effective_received_amount,
op_id: operation.id,
succeed: _op_return.1,
fee: operation.content.fee,
Expand All @@ -1286,6 +1309,7 @@ impl ExecutionState {
from: operation.content_creator_address,
to: *target_addr,
amount: *coins,
effective_received_amount: *coins,
op_id: operation.id,
succeed: _op_return.1,
fee: operation.content.fee,
Expand Down
5 changes: 5 additions & 0 deletions massa-node/base_config/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3151,6 +3151,7 @@
"from",
"to",
"amount",
"effective_amount_received",
"context",
"succeed",
"fee",
Expand All @@ -3170,6 +3171,10 @@
"description": "Amount transferred",
"type": "integer"
},
"effective_amount_received": {
"description": "Amount received by the receiver",
"type": "integer"
},
"context": {
"description": "Context of the transfer : operation or asyncronous execution",
"type": "object"
Expand Down

0 comments on commit df156f3

Please sign in to comment.