Skip to content

Commit 85df9a6

Browse files
fix: follow the js api
Signed-off-by: Ivaylo Nikolov <[email protected]>
1 parent e34a671 commit 85df9a6

File tree

5 files changed

+22
-57
lines changed

5 files changed

+22
-57
lines changed

examples/transfer_with_hooks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async fn main() -> anyhow::Result<()> {
206206
// Transaction 1: HBAR transfers with hook
207207
println!("\n1. Executing HBAR TransferTransaction with hook...");
208208
TransferTransaction::new()
209-
.hbar_transfer_with_hook(sender_account_id, Hbar::from_tinybars(-1), hbar_hook)
209+
.add_hbar_transfer_with_hook(sender_account_id, Hbar::from_tinybars(-1), hbar_hook)
210210
.hbar_transfer(receiver_account_id, Hbar::from_tinybars(1))
211211
.freeze_with(&client)?
212212
.sign(sender_key.clone())
@@ -219,7 +219,7 @@ async fn main() -> anyhow::Result<()> {
219219
// Transaction 2: NFT transfer with sender and receiver hooks
220220
println!("\n2. Executing NFT TransferTransaction with hooks...");
221221
TransferTransaction::new()
222-
.nft_transfer_with_both_hooks(
222+
.add_nft_transfer_with_hook(
223223
nft_id,
224224
sender_account_id,
225225
receiver_account_id,
@@ -237,7 +237,7 @@ async fn main() -> anyhow::Result<()> {
237237
// Transaction 3: Fungible token transfers with hook
238238
println!("\n3. Executing Fungible Token TransferTransaction with hook...");
239239
TransferTransaction::new()
240-
.token_transfer_with_hook(
240+
.add_token_transfer_with_hook(
241241
fungible_token_id,
242242
sender_account_id,
243243
-1_000,

src/hooks/fungible_hook_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use hedera_proto::services;
22

33
use crate::hooks::{
4-
EvmHookCall,
54
FungibleHookType,
65
HookCall,
76
};
@@ -45,6 +44,7 @@ impl ToProtobuf for FungibleHookCall {
4544
#[cfg(test)]
4645
mod tests {
4746
use super::*;
47+
use crate::hooks::EvmHookCall;
4848

4949
#[test]
5050
fn test_fungible_hook_call_creation() {

src/hooks/nft_hook_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use hedera_proto::services;
22

33
use crate::hooks::{
4-
EvmHookCall,
54
HookCall,
65
NftHookType,
76
};
@@ -45,6 +44,7 @@ impl ToProtobuf for NftHookCall {
4544
#[cfg(test)]
4645
mod tests {
4746
use super::*;
47+
use crate::hooks::EvmHookCall;
4848

4949
#[test]
5050
fn test_nft_hook_call_creation() {

src/transfer_transaction.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -305,28 +305,6 @@ impl TransferTransaction {
305305
self._hbar_transfer(account_id, amount, false, Some(hook_call))
306306
}
307307

308-
/// Add an NFT transfer with a sender hook call.
309-
pub fn nft_transfer_with_sender_hook(
310-
&mut self,
311-
nft_id: impl Into<NftId>,
312-
sender: AccountId,
313-
receiver: AccountId,
314-
sender_hook_call: NftHookCall,
315-
) -> &mut Self {
316-
self._nft_transfer(nft_id.into(), sender, receiver, false, Some(sender_hook_call), None)
317-
}
318-
319-
/// Add an NFT transfer with a receiver hook call.
320-
pub fn nft_transfer_with_receiver_hook(
321-
&mut self,
322-
nft_id: impl Into<NftId>,
323-
sender: AccountId,
324-
receiver: AccountId,
325-
receiver_hook_call: NftHookCall,
326-
) -> &mut Self {
327-
self._nft_transfer(nft_id.into(), sender, receiver, false, None, Some(receiver_hook_call))
328-
}
329-
330308
/// Add a token transfer with a fungible hook call.
331309
pub fn add_token_transfer_with_hook(
332310
&mut self,
@@ -338,29 +316,8 @@ impl TransferTransaction {
338316
self._token_transfer(token_id, account_id, amount, false, None, Some(hook_call))
339317
}
340318

341-
/// Add a hbar transfer with a fungible hook call.
342-
pub fn hbar_transfer_with_hook(
343-
&mut self,
344-
account_id: AccountId,
345-
amount: Hbar,
346-
hook_call: FungibleHookCall,
347-
) -> &mut Self {
348-
self._hbar_transfer(account_id, amount, false, Some(hook_call))
349-
}
350-
351-
/// Add a token transfer with a fungible hook call.
352-
pub fn token_transfer_with_hook(
353-
&mut self,
354-
token_id: TokenId,
355-
account_id: AccountId,
356-
amount: i64,
357-
hook_call: FungibleHookCall,
358-
) -> &mut Self {
359-
self._token_transfer(token_id, account_id, amount, false, None, Some(hook_call))
360-
}
361-
362319
/// Add an NFT transfer with both sender and receiver hook calls.
363-
pub fn nft_transfer_with_both_hooks(
320+
pub fn add_nft_transfer_with_hook(
364321
&mut self,
365322
nft_id: impl Into<NftId>,
366323
sender: AccountId,

tests/e2e/token/transfer_with_hooks.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async fn can_transfer_hbar_with_pre_tx_allowance_hook() -> anyhow::Result<()> {
9595

9696
// Perform transfer with hook
9797
let transfer_receipt = TransferTransaction::new()
98-
.hbar_transfer_with_hook(sender_id, Hbar::from_tinybars(-100), fungible_hook_call)
98+
.add_hbar_transfer_with_hook(sender_id, Hbar::from_tinybars(-100), fungible_hook_call)
9999
.hbar_transfer(receiver_id, Hbar::from_tinybars(100))
100100
.freeze_with(&client)?
101101
.sign(sender_key)
@@ -160,7 +160,7 @@ async fn can_transfer_hbar_with_pre_post_tx_allowance_hook() -> anyhow::Result<(
160160

161161
// Perform transfer with hook
162162
let transfer_receipt = TransferTransaction::new()
163-
.hbar_transfer_with_hook(sender_id, Hbar::from_tinybars(-100), fungible_hook_call)
163+
.add_hbar_transfer_with_hook(sender_id, Hbar::from_tinybars(-100), fungible_hook_call)
164164
.hbar_transfer(receiver_id, Hbar::from_tinybars(100))
165165
.freeze_with(&client)?
166166
.sign(sender_key)
@@ -247,7 +247,7 @@ async fn can_transfer_fungible_token_with_hook() -> anyhow::Result<()> {
247247

248248
// Perform token transfer with hook
249249
let transfer_receipt = TransferTransaction::new()
250-
.token_transfer_with_hook(token_id, sender_id, -10, fungible_hook_call)
250+
.add_token_transfer_with_hook(token_id, sender_id, -10, fungible_hook_call)
251251
.token_transfer(token_id, receiver_id, 10)
252252
.freeze_with(&client)?
253253
.sign(sender_key)
@@ -342,13 +342,18 @@ async fn can_transfer_nft_with_sender_hook() -> anyhow::Result<()> {
342342
let hook_call = HookCall::new(Some(1), Some(evm_hook_call));
343343
let sender_nft_hook_call = NftHookCall { hook_call, hook_type: NftHookType::PreHookSender };
344344

345-
// Perform NFT transfer with sender hook
345+
// Perform NFT transfer with sender hook (receiver hook is dummy/empty)
346+
let dummy_receiver_hook = NftHookCall {
347+
hook_call: HookCall::new(None, None),
348+
hook_type: NftHookType::PreHookReceiver,
349+
};
346350
let transfer_receipt = TransferTransaction::new()
347-
.nft_transfer_with_sender_hook(
351+
.add_nft_transfer_with_hook(
348352
token_id.nft(serial_number),
349353
sender_id,
350354
receiver_id,
351355
sender_nft_hook_call,
356+
dummy_receiver_hook,
352357
)
353358
.freeze_with(&client)?
354359
.sign(sender_key)
@@ -443,12 +448,15 @@ async fn can_transfer_nft_with_receiver_hook() -> anyhow::Result<()> {
443448
let hook_call = HookCall::new(Some(1), Some(evm_hook_call));
444449
let receiver_nft_hook_call = NftHookCall { hook_call, hook_type: NftHookType::PreHookReceiver };
445450

446-
// Perform NFT transfer with receiver hook
451+
// Perform NFT transfer with receiver hook (sender hook is dummy/empty)
452+
let dummy_sender_hook =
453+
NftHookCall { hook_call: HookCall::new(None, None), hook_type: NftHookType::PreHookSender };
447454
let transfer_receipt = TransferTransaction::new()
448-
.nft_transfer_with_receiver_hook(
455+
.add_nft_transfer_with_hook(
449456
token_id.nft(serial_number),
450457
sender_id,
451458
receiver_id,
459+
dummy_sender_hook,
452460
receiver_nft_hook_call,
453461
)
454462
.freeze_with(&client)?
@@ -556,7 +564,7 @@ async fn can_transfer_nft_with_both_sender_and_receiver_hooks() -> anyhow::Resul
556564

557565
// Perform NFT transfer with both hooks
558566
let transfer_receipt = TransferTransaction::new()
559-
.nft_transfer_with_both_hooks(
567+
.add_nft_transfer_with_hook(
560568
token_id.nft(serial_number),
561569
sender_id,
562570
receiver_id,

0 commit comments

Comments
 (0)