Skip to content

Commit

Permalink
Problem: Missing transaction receipt support for metaverse demo (cron…
Browse files Browse the repository at this point in the history
  • Loading branch information
damoncro committed May 25, 2023
1 parent f2f845d commit 396c190
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Metaverse/Source/Metaverse/MetaverseCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "DefiWalletCoreActor.h"
#include "Logging/LogVerbosity.h"
#include "DynamicContractObject.h"
#include "Utlis.h"

// AMetaverseCharacter
AMetaverseCharacter::AMetaverseCharacter() {
Expand Down Expand Up @@ -229,3 +230,27 @@ AMetaverseCharacter::CreateDynamicContract(FString contractaddress,
return DefiWalletCore->CreateDynamicContract(contractaddress, abijson,
success, output_message);
}


void AMetaverseCharacter::WaitForTransactionReceipt(TArray<uint8_t> 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);
}
3 changes: 3 additions & 0 deletions Metaverse/Source/Metaverse/MetaverseCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ class AMetaverseCharacter : public ACharacter {
FString abijson,
bool &success,
FString &output_message);

void WaitForTransactionReceipt(TArray<uint8_t> tx_hash);
void OnTransactionReceipt(FString TxReceipt, FString Result);
};
9 changes: 7 additions & 2 deletions Metaverse/Source/Metaverse/Private/NPC/Erc20Transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ void AErc20Transfer::OnErc20TransferBeginOverlap(
UPrimitiveComponent *OverlappedComponent, AActor *OtherActor,
UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult &SweepResult) {
AMetaverseCharacter *MetaverseCharacter =
Cast<AMetaverseCharacter>(OtherActor);
MetaverseCharacter = Cast<AMetaverseCharacter>(OtherActor);
if (MetaverseCharacter->GetAccount().IsEmpty()) {
MetaverseCharacter->SetAccount(
FText::FromString(FString::Printf(TEXT("Plase scan QR Code"))));
Expand All @@ -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
}
}
2 changes: 2 additions & 0 deletions Metaverse/Source/Metaverse/Private/NPC/SendEthTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 2 additions & 0 deletions Metaverse/Source/Metaverse/Public/NPC/Erc20Transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Erc20Transfer.generated.h"

struct FWalletSendTXEip155Result;
class AMetaverseCharacter;

/**
*
Expand All @@ -28,4 +29,5 @@ class METAVERSE_API AErc20Transfer : public AHelp {
private:
UFUNCTION()
void OnWalletconnectErc20TranferFinished(FWalletSendTXEip155Result TxResult);
AMetaverseCharacter *MetaverseCharacter;
};

0 comments on commit 396c190

Please sign in to comment.