Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions escrow/SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ pub enum EscrowStatus {
### EscrowData (Struct)
```rust
pub struct EscrowData<M: ManagedTypeApi> {
pub employer: ManagedAddress<M>, // Who deposited the funds
pub receiver: ManagedAddress<M>, // Who receives on release (agent)
pub token_id: EgldOrEsdtTokenIdentifier<M>, // EGLD or ESDT token
pub token_nonce: u64, // SFT/NFT nonce (0 for fungible)
pub amount: BigUint<M>, // Locked amount
pub poa_hash: ManagedBuffer<M>, // Proof-of-Agreement hash
pub deadline: u64, // Unix timestamp (seconds)
pub status: EscrowStatus, // Current state
/// Who deposited the funds
pub employer: ManagedAddress<M>,
/// Who receives on release (agent)
pub receiver: ManagedAddress<M>,
/// Payment details: token, nonce, amount
pub payment: Payment<M>,
/// Proof-of-Agreement hash
pub poa_hash: ManagedBuffer<M>,
/// Unix timestamp (seconds) of the block for the escrow deadline
pub deadline: TimestampSeconds,
/// Current state of the escrow
pub status: EscrowStatus,
}
```

Expand Down Expand Up @@ -200,7 +204,7 @@ The `release` function reads job data directly from the Validation Registry's st
### 5.4 Zero-Allocation Compliance

The contract uses **only** `Managed*` types:
- `ManagedBuffer`, `ManagedAddress`, `BigUint`, `EgldOrEsdtTokenIdentifier`
- `ManagedBuffer`, `ManagedAddress`, `BigUint`, `TokenId`
- No `String`, `Vec`, `Box`, `HashMap`, `format!`, or `alloc` anywhere
- `#![no_std]` at the crate root

Expand Down
3 changes: 3 additions & 0 deletions escrow/multiversx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"language": "rust"
}
1 change: 0 additions & 1 deletion escrow/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ pub const ERR_JOB_NOT_VERIFIED: &str = "Job must be verified before release";
pub const ERR_DEADLINE_NOT_PASSED: &str = "Deadline has not passed yet";
pub const ERR_DEADLINE_IN_PAST: &str = "Deadline must be in the future";
pub const ERR_ALREADY_SETTLED: &str = "Escrow already settled";
pub const ERR_ZERO_DEPOSIT: &str = "Deposit amount must be greater than zero";
12 changes: 6 additions & 6 deletions escrow/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ multiversx_sc::imports!();

#[multiversx_sc::module]
pub trait EventsModule {
#[event("escrow_deposited")]
#[event("escrowDeposited")]
fn escrow_deposited_event(
&self,
#[indexed] job_id: &ManagedBuffer,
#[indexed] employer: &ManagedAddress,
amount: BigUint,
amount: &NonZeroBigUint,
);

#[event("escrow_released")]
#[event("escrowReleased")]
fn escrow_released_event(
&self,
#[indexed] job_id: &ManagedBuffer,
#[indexed] receiver: &ManagedAddress,
amount: BigUint,
amount: &NonZeroBigUint,
);

#[event("escrow_refunded")]
#[event("escrowRefunded")]
fn escrow_refunded_event(
&self,
#[indexed] job_id: &ManagedBuffer,
#[indexed] employer: &ManagedAddress,
amount: BigUint,
amount: &NonZeroBigUint,
);
}
29 changes: 9 additions & 20 deletions escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ pub trait EscrowContract:
poa_hash: ManagedBuffer,
deadline: TimestampSeconds,
) {
let payment = self.call_value().egld_or_single_esdt();
require!(payment.amount > 0u64, ERR_ZERO_DEPOSIT);
let payment = self.call_value().single();

let current_timestamp = self.blockchain().get_block_timestamp_seconds();
require!(deadline > current_timestamp, ERR_DEADLINE_IN_PAST);
Expand All @@ -59,9 +58,7 @@ pub trait EscrowContract:
let escrow = EscrowData {
employer: caller.clone(),
receiver,
token_id: payment.token_identifier.clone(),
token_nonce: payment.token_nonce,
amount: payment.amount.clone(),
payment: payment.clone(),
poa_hash,
deadline,
status: EscrowStatus::Active,
Expand All @@ -70,7 +67,7 @@ pub trait EscrowContract:
// Effects: store escrow
escrow_mapper.set(&escrow);

self.escrow_deposited_event(&job_id, &caller, payment.amount);
self.escrow_deposited_event(&job_id, &caller, &payment.amount);
}

/// Release escrowed funds to the receiver.
Expand Down Expand Up @@ -99,19 +96,15 @@ pub trait EscrowContract:

// Effects: mark as released BEFORE interactions
escrow.status = EscrowStatus::Released;
let receiver = escrow.receiver.clone();
let amount = escrow.amount.clone();
let token_id = escrow.token_id.clone();
let token_nonce = escrow.token_nonce;
escrow_mapper.set(&escrow);

// Interactions: transfer funds to receiver
self.tx()
.to(&receiver)
.egld_or_single_esdt(&token_id, token_nonce, &amount)
.to(&escrow.receiver)
.payment(&escrow.payment)
.transfer();

self.escrow_released_event(&job_id, &receiver, amount);
self.escrow_released_event(&job_id, &escrow.receiver, &escrow.payment.amount);
}

/// Refund escrowed funds to the employer if the deadline has passed.
Expand All @@ -129,18 +122,14 @@ pub trait EscrowContract:

// Effects: mark as refunded BEFORE interactions
escrow.status = EscrowStatus::Refunded;
let employer = escrow.employer.clone();
let amount = escrow.amount.clone();
let token_id = escrow.token_id.clone();
let token_nonce = escrow.token_nonce;
escrow_mapper.set(&escrow);

// Interactions: transfer funds back to employer
self.tx()
.to(&employer)
.egld_or_single_esdt(&token_id, token_nonce, &amount)
.to(&escrow.employer)
.payment(&escrow.payment)
.transfer();

self.escrow_refunded_event(&job_id, &employer, amount);
self.escrow_refunded_event(&job_id, &escrow.employer, &escrow.payment.amount);
}
}
10 changes: 7 additions & 3 deletions escrow/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ pub enum EscrowStatus {
#[type_abi]
#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, Debug)]
pub struct EscrowData<M: ManagedTypeApi> {
/// Who deposited the funds
pub employer: ManagedAddress<M>,
/// Who receives on release (agent)
pub receiver: ManagedAddress<M>,
pub token_id: EgldOrEsdtTokenIdentifier<M>,
pub token_nonce: u64,
pub amount: BigUint<M>,
/// Payment details: token, nonce, amount
pub payment: Payment<M>,
/// Proof-of-Agreement hash
pub poa_hash: ManagedBuffer<M>,
/// Unix timestamp (seconds) of the block for the escrow deadline
pub deadline: TimestampSeconds,
/// Current state of the escrow
pub status: EscrowStatus,
}

Expand Down
8 changes: 2 additions & 6 deletions identity-registry/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ pub trait ViewsModule: crate::storage::StorageModule {
&self,
nonce: u64,
service_id: u32,
) -> OptionalValue<EgldOrEsdtTokenPayment<Self::Api>> {
) -> OptionalValue<Payment<Self::Api>> {
let mapper = self.agent_service_config(nonce);
if let Some(payment) = mapper.get(&service_id) {
OptionalValue::Some(EgldOrEsdtTokenPayment::new(
EgldOrEsdtTokenIdentifier::from(payment.token_identifier),
payment.token_nonce,
payment.amount.into_big_uint(),
))
OptionalValue::Some(payment)
} else {
OptionalValue::None
}
Expand Down
2 changes: 0 additions & 2 deletions tests/src/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ impl CsInteract {

// ── Reputation Registry ──


pub async fn give_feedback_simple(
&mut self,
from: &Address,
Expand Down Expand Up @@ -507,7 +506,6 @@ impl CsInteract {
.await;
}


pub async fn submit_proof_expect_err(
&mut self,
from: &Address,
Expand Down
2 changes: 0 additions & 2 deletions tests/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ impl AgentTestState {

// ── Reputation Registry ──


pub fn give_feedback_simple(
&mut self,
from: &multiversx_sc::types::TestAddress,
Expand Down Expand Up @@ -1104,7 +1103,6 @@ impl AgentTestState {
.run();
}


pub fn append_response_expect_err(
&mut self,
from: &multiversx_sc::types::TestAddress,
Expand Down
Loading
Loading