diff --git a/Metaverse/Source/Metaverse/MetaverseCharacter.cpp b/Metaverse/Source/Metaverse/MetaverseCharacter.cpp index 6e0faee..cf2c3ea 100644 --- a/Metaverse/Source/Metaverse/MetaverseCharacter.cpp +++ b/Metaverse/Source/Metaverse/MetaverseCharacter.cpp @@ -16,6 +16,7 @@ #include "DefiWalletCoreActor.h" #include "Logging/LogVerbosity.h" #include "DynamicContractObject.h" +#include "Utlis.h" // AMetaverseCharacter AMetaverseCharacter::AMetaverseCharacter() { @@ -229,3 +230,27 @@ AMetaverseCharacter::CreateDynamicContract(FString contractaddress, return DefiWalletCore->CreateDynamicContract(contractaddress, abijson, success, output_message); } + + +void AMetaverseCharacter::WaitForTransactionReceipt(TArray tx_hash) { + ADefiWalletCoreActor *DefiWalletCore = + DefiWalletCoreComponent->GetDefiWalletCore(); + if (DefiWalletCore) { + UE_LOG(LogTemp, Log, TEXT("Getting Transaction Receipt from: %s..."), + *UUtlis::ToHex(tx_hash)); + DefiWalletCore->OnTransactionReceiptDelegate.BindDynamic( + this, &AMetaverseCharacter::OnTransactionReceipt); + // use the internal delegate + // TODO use the customized delegate + DefiWalletCore->WaitForTransactionReceipt( + tx_hash, DefiWalletCore->OnTransactionReceiptDelegate); + } else { + UE_LOG(LogTemp, Error, TEXT("Can not find Defi Wallet Core")); + } +} + +void AMetaverseCharacter::OnTransactionReceipt(FString TxReceipt, + FString Result) { + UE_LOG(LogTemp, Log, TEXT("Transaction Receipt : %s, Result: %s"), + *TxReceipt, *Result); +} diff --git a/Metaverse/Source/Metaverse/MetaverseCharacter.h b/Metaverse/Source/Metaverse/MetaverseCharacter.h index 0b2d507..7097e40 100644 --- a/Metaverse/Source/Metaverse/MetaverseCharacter.h +++ b/Metaverse/Source/Metaverse/MetaverseCharacter.h @@ -101,4 +101,7 @@ class AMetaverseCharacter : public ACharacter { FString abijson, bool &success, FString &output_message); + + void WaitForTransactionReceipt(TArray tx_hash); + void OnTransactionReceipt(FString TxReceipt, FString Result); }; diff --git a/Metaverse/Source/Metaverse/Private/NPC/Erc20Transfer.cpp b/Metaverse/Source/Metaverse/Private/NPC/Erc20Transfer.cpp index 77122b8..cbed7fb 100644 --- a/Metaverse/Source/Metaverse/Private/NPC/Erc20Transfer.cpp +++ b/Metaverse/Source/Metaverse/Private/NPC/Erc20Transfer.cpp @@ -18,8 +18,7 @@ void AErc20Transfer::OnErc20TransferBeginOverlap( UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult) { - AMetaverseCharacter *MetaverseCharacter = - Cast(OtherActor); + MetaverseCharacter = Cast(OtherActor); if (MetaverseCharacter->GetAccount().IsEmpty()) { MetaverseCharacter->SetAccount( FText::FromString(FString::Printf(TEXT("Plase scan QR Code")))); @@ -45,4 +44,10 @@ void AErc20Transfer::OnWalletconnectErc20TranferFinished( FWalletSendTXEip155Result TxResult) { UE_LOG(LogTemp, Log, TEXT("Transaction Hash: %s, Result: %s"), *UUtlis::ToHex(TxResult.tx_hash), *TxResult.result); + // Update new balance + // TODO Check transaction receipt before querying the balance + if (MetaverseCharacter) { + MetaverseCharacter->WaitForTransactionReceipt(TxResult.tx_hash); + //TODO check receipt valid or not + } } diff --git a/Metaverse/Source/Metaverse/Private/NPC/SendEthTransaction.cpp b/Metaverse/Source/Metaverse/Private/NPC/SendEthTransaction.cpp index 6eb86be..d12a442 100644 --- a/Metaverse/Source/Metaverse/Private/NPC/SendEthTransaction.cpp +++ b/Metaverse/Source/Metaverse/Private/NPC/SendEthTransaction.cpp @@ -50,6 +50,8 @@ void ASendEthTransaction::OnWalletconnectSendEip155TransactionFinished( // Update new balance // TODO Check transaction receipt before querying the balance if (MetaverseCharacter) { + MetaverseCharacter->WaitForTransactionReceipt(SendResult.tx_hash); + // TODO check receipt valid or not MetaverseCharacter->SetBalance(MetaverseCharacter->GetAccount()); } } diff --git a/Metaverse/Source/Metaverse/Public/NPC/Erc20Transfer.h b/Metaverse/Source/Metaverse/Public/NPC/Erc20Transfer.h index 1bc7beb..686e2b3 100644 --- a/Metaverse/Source/Metaverse/Public/NPC/Erc20Transfer.h +++ b/Metaverse/Source/Metaverse/Public/NPC/Erc20Transfer.h @@ -7,6 +7,7 @@ #include "Erc20Transfer.generated.h" struct FWalletSendTXEip155Result; +class AMetaverseCharacter; /** * @@ -28,4 +29,5 @@ class METAVERSE_API AErc20Transfer : public AHelp { private: UFUNCTION() void OnWalletconnectErc20TranferFinished(FWalletSendTXEip155Result TxResult); + AMetaverseCharacter *MetaverseCharacter; };