Skip to content

Commit

Permalink
Problem: Metaverse example not updated (fix #330) (#50)
Browse files Browse the repository at this point in the history
tidy up

remove debug display

callback in app

tidy up

restore

update dynamic contract info

fix ci

fix ci

use ue 5.2

setup

update walletconnect

fix ue4

remove umap

restore file
  • Loading branch information
leejw51crypto authored Jul 10, 2023
1 parent 5c045f3 commit 3972975
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 52 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/local/lib/android
- name: Checkout play-unreal-plugin repo
uses: actions/checkout@v3
Expand All @@ -36,6 +36,7 @@ jobs:
- name: Build play-unreal-plugin repo
run: |
cd simple/Plugins/play-unreal-plugin
mv ./Source/ThirdParty/PlayCppSdkLibrary/PlayCppSdkLibrary.Build.cs.legacy ./Source/ThirdParty/PlayCppSdkLibrary/PlayCppSdkLibrary.Build.cs
TARGET=4.27 make
python change_version.py 4.27.0
sudo chmod 777 -R $GITHUB_WORKSPACE
Expand Down Expand Up @@ -94,16 +95,17 @@ jobs:
- name: Build play-unreal-plugin repo
run: |
cd Metaverse/Plugins/play-unreal-plugin
TARGET=5.1 make
python change_version.py 5.1.0
mv ./Source/ThirdParty/PlayCppSdkLibrary/PlayCppSdkLibrary.Build.cs.legacy ./Source/ThirdParty/PlayCppSdkLibrary/PlayCppSdkLibrary.Build.cs
TARGET=5.2 make
python change_version.py 5.2.0
sudo chmod 777 -R $GITHUB_WORKSPACE
- uses: addnab/docker-run-action@v3
with:
registry: ghcr.io
username: ${{ secrets.USER }}
password: ${{ secrets.PAT }}
image: ghcr.io/epicgames/unreal-engine:dev-slim-5.1
image: ghcr.io/epicgames/unreal-engine:dev-slim-5.2
options: -v ${{ github.workspace }}:/home/ue4/play-unreal-demo -e HOME=/home/ue4
run: |
cd ~/play-unreal-demo/Metaverse
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
*.json
*.tar
*.swp
*.sh

# Visual Studio 2015 user specific files
.vs/

Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion Metaverse/Metaverse.uproject
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "5.1",
"EngineAssociation": "5.2",
"Category": "",
"Description": "",
"Modules": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void UDefiWalletCoreComponent::Setup() {
// NewDefiWalletCore->myCronosChainID = 25;
// NewDefiWalletCore->myCronosRpc = "https://evm-dev.cronos.org/";
NewDefiWalletCore->myCronosChainID = 338;
NewDefiWalletCore->myCronosRpc = "https://evm-t3.cronos.org";
NewDefiWalletCore->myCronosRpc = "https://evm-dev-t3.cronos.org";
UE_LOG(LogTemp, Display, TEXT("%s was created"),
*NewDefiWalletCore->GetActorNameOrLabel());
_DefiWalletCore = NewDefiWalletCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,28 @@ APlayCppSdkActor *UWalletConnectTriggerComponent::Setup() {
(APlayCppSdkActor *)UGameplayStatics::GetActorOfClass(
GetWorld(), APlayCppSdkActor::StaticClass());

FString description = "Defi WalletConnect example.";
FString url = "http://localhost:8080/";
TArray<FString> icon_urls;
FString name = "New Defi WalletConnect Web3 Example";
int64 chain_id = 338;

std::string userrelayserver="wss://relay.walletconnect.com";
std::string userprojectid="";
std::string userwalletnamespace =
"{\"eip155\":{\"methods\":[\"eth_sendTransaction\",\"eth_"
"signTransaction\",\"eth_sign\",\"personal_sign\",\"eth_"
"signTypedData\"],\"chains\":[\"eip155:5\"],\"events\":["
"\"chainChanged\",\"accountsChanged\"]}}";
std::string userclientmeta=
"{\"description\":\"Defi WalletConnect v2 "
"example.\",\"url\":\"http://localhost:8080/"
"\",\"icons\":[],\"name\":\"Defi WalletConnect Web3 Example\"}";

const char* projectId = std::getenv("NEXT_PUBLIC_PROJECT_ID");
if (projectId != nullptr) {
userprojectid = projectId;
}
// print projectid to unreal
UE_LOG(LogTemp, Display, TEXT("NEXT_PUBLIC_PROJECT_ID: %s"),
UTF8_TO_TCHAR(userprojectid.c_str()));


EConnectionType connection_type = EConnectionType::QR_TEXTURE;

if (PlayCppSdk) {
Expand All @@ -50,8 +67,12 @@ APlayCppSdkActor *UWalletConnectTriggerComponent::Setup() {
break;
case EWalletconnectSessionState::StateInit:
case EWalletconnectSessionState::StateDisconnected: {
PlayCppSdk->ConnectWalletConnect(description, url, icon_urls, name,
chain_id, connection_type);
PlayCppSdk->ConnectWalletConnect(
UTF8_TO_TCHAR(userrelayserver.c_str()),
UTF8_TO_TCHAR(userprojectid.c_str()),
UTF8_TO_TCHAR(userwalletnamespace.c_str()),
UTF8_TO_TCHAR(userclientmeta.c_str()),
connection_type);
break;
}
case EWalletconnectSessionState::StateRestored:
Expand All @@ -63,8 +84,17 @@ APlayCppSdkActor *UWalletConnectTriggerComponent::Setup() {
APlayCppSdkActor *NewPlayCppSdk =
(APlayCppSdkActor *)GetWorld()->SpawnActor(
APlayCppSdkActor::StaticClass());
NewPlayCppSdk->ConnectWalletConnect(description, url, icon_urls, name,
chain_id, connection_type);

NewPlayCppSdk->OnReceiveWalletconnectPollingDelegate.BindDynamic(
this, &UWalletConnectTriggerComponent::OnReceiveWalletconnectPolling);

NewPlayCppSdk->PollingEventsEnabled=true;
NewPlayCppSdk->ConnectWalletConnect(
UTF8_TO_TCHAR(userrelayserver.c_str()),
UTF8_TO_TCHAR(userprojectid.c_str()),
UTF8_TO_TCHAR(userwalletnamespace.c_str()),
UTF8_TO_TCHAR(userclientmeta.c_str()),
connection_type);
UE_LOG(LogTemp, Display, TEXT("%s was created"),
*NewPlayCppSdk->GetActorNameOrLabel());
return NewPlayCppSdk;
Expand All @@ -77,27 +107,19 @@ void UWalletConnectTriggerComponent::OnQRReadyFinished(UTexture2D *Texture) {
this->OnShowQR.ExecuteIfBound(Texture);
}

void UWalletConnectTriggerComponent::
OnReceiveWalletconnectSessionInfoDelegateFinished(
FWalletConnectSessionInfo SessionInfo) {
// Monitor the walletconnect events
UE_LOG(LogTemp, Display, TEXT("Got %s event: %s"),
*_PlayCppSdk->GetActorNameOrLabel(),
*UEnum::GetValueAsString(SessionInfo.sessionstate))
switch (SessionInfo.sessionstate) {
case EWalletconnectSessionState::StateConnecting:
break;
case EWalletconnectSessionState::StateConnected:
break;
case EWalletconnectSessionState::StateUpdated:
break;
case EWalletconnectSessionState::StateDisconnected:
break;
default:
break;

void UWalletConnectTriggerComponent::OnReceiveWalletconnectPolling(FString jsonevent,
FString result) {

// if result is empty, print log
if (result.IsEmpty()) {
UE_LOG(LogTemp, Log, TEXT("App ReceiveEvent= %s"), *jsonevent);
}

_PlayCppSdk->BeginPolling(_PlayCppSdk->OnReceiveWalletconnectPollingDelegate);
}


//
// Connect
//
Expand All @@ -123,9 +145,7 @@ void UWalletConnectTriggerComponent::Connect() {
_PlayCppSdk->OnQRReady.BindDynamic(
this, &UWalletConnectTriggerComponent::OnQRReadyFinished);

_PlayCppSdk->OnReceiveWalletconnectSessionInfoDelegate.BindDynamic(
this, &UWalletConnectTriggerComponent::OnReceiveWalletconnectSessionInfoDelegateFinished);


break;
}
case EWalletconnectSessionState::StateConnecting:
Expand Down
110 changes: 108 additions & 2 deletions Metaverse/Source/Metaverse/Private/NPC/CallDynamicContract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,117 @@ void ACallDynamicContract::BeginPlay() {
this, &ACallDynamicContract::OnCallDynamicContract);
}

void ACallDynamicContract::Setup() {
const char *contractId = std::getenv("MYCONTRACT721");
std::string usercontractId = "";
if (contractId != nullptr) {
usercontractId = contractId;
}
UE_LOG(LogTemp, Display, TEXT("MYCONTRACT721: %s"),
UTF8_TO_TCHAR(usercontractId.c_str()));
UserContractAddress = UTF8_TO_TCHAR(usercontractId.c_str());

UserContractAbiJson = TEXT(
"[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":"
"\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,"
"\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},"
"{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\","
"\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\","
"\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\","
"\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":"
"true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":"
"\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":"
"\"operator\",\"type\":\"address\"},{\"indexed\":false,"
"\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],"
"\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,"
"\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":"
"\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,"
"\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":"
"\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{"
"\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":"
"\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,"
"\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{"
"\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\","
"\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{"
"\"inputs\":[],\"name\":\"_tokenIdCounter\",\"outputs\":[{"
"\"internalType\":\"uint256\",\"name\":\"_value\",\"type\":\"uint256\"}"
"],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{"
"\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{"
"\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":"
"\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"stateMutability\":"
"\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":"
"\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":"
"\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":"
"\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":"
"\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":"
"\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\","
"\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":"
"\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{"
"\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":"
"\"address\"},{\"internalType\":\"address\",\"name\":\"operator\","
"\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{"
"\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],"
"\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],"
"\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":"
"\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":"
"\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{"
"\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],"
"\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{"
"\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":"
"\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":"
"\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":"
"\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":"
"\"renounceOwnership\",\"outputs\":[],\"stateMutability\":"
"\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":"
"\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":"
"\"string\",\"name\":\"uri\",\"type\":\"string\"}],\"name\":"
"\"safeMint\",\"outputs\":[],\"stateMutability\":\"nonpayable\","
"\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\","
"\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\","
"\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\","
"\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":"
"\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":"
"\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":"
"\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":"
"\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":"
"\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{"
"\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],"
"\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":"
"\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":"
"\"address\",\"name\":\"operator\",\"type\":\"address\"},{"
"\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],"
"\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":"
"\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":"
"\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":"
"\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\","
"\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\","
"\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":"
"[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],"
"\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{"
"\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":"
"\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"internalType\":"
"\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":"
"\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":"
"\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":"
"\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":"
"\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":"
"\"transferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\","
"\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\","
"\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":"
"\"transferOwnership\",\"outputs\":[],\"stateMutability\":"
"\"nonpayable\",\"type\":\"function\"}]");
UserFunctionName = TEXT("ownerOf");
UserFunctionArgs = TEXT("[{\"Uint\":{\"data\":\"2\"}}]");
}

void ACallDynamicContract::OnCallDynamicContractBeginOverlap(
UPrimitiveComponent *OverlappedComponent, AActor *OtherActor,
UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult &SweepResult) {

// setup contract
Setup();

AMetaverseCharacter *MetaverseCharacter =
Cast<AMetaverseCharacter>(OtherActor);
if (MetaverseCharacter != nullptr) {
Expand All @@ -37,7 +143,7 @@ void ACallDynamicContract::OnCallDynamicContractBeginOverlap(
TEXT("CreateDynamicContract success: %s, output_message: "
"%s"),
success ? TEXT("true") : TEXT("false"), *output_message);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Blue, ouput);
GEngine->AddOnScreenDebugMessage(-1, 60.f, FColor::Blue, ouput);
}
}

Expand All @@ -55,6 +161,6 @@ void ACallDynamicContract::OnCallDynamicContract(FString JsonResult,
FString ouput = FString::Printf(
TEXT("OnCallDynamicContract JsonResult: %s, Result: %s"),
*JsonResult, *Result);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, ouput);
GEngine->AddOnScreenDebugMessage(-1, 60.f, FColor::Red, ouput);
}
}
3 changes: 2 additions & 1 deletion Metaverse/Source/Metaverse/Private/NPC/Erc20Transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void AErc20Transfer::OnErc20TransferBeginOverlap(

WalletConnectTriggerComponent->Erc20Transfer(
"0xC213a7B37F4f7eC81f78895E50EA773aA8E78255",
"0xA914161b1b8d9dbC9c5310Fc7EBee5A5B18044b7", "1000000000000000000", "", "");
"0xA914161b1b8d9dbC9c5310Fc7EBee5A5B18044b7", "1000000000000000000", "",
"");

WalletConnectTriggerComponent->OnShowQR.BindDynamic(this, &Super::ShowQR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DECLARE_DYNAMIC_DELEGATE(FHideQR);
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class METAVERSE_API UWalletConnectTriggerComponent : public USphereComponent {
GENERATED_BODY()
private:
public:
APlayCppSdkActor *_PlayCppSdk;

APlayCppSdkActor *Setup();
Expand Down Expand Up @@ -71,8 +71,7 @@ class METAVERSE_API UWalletConnectTriggerComponent : public USphereComponent {
void OnQRReadyFinished(UTexture2D *Texture);

UFUNCTION()
void OnReceiveWalletconnectSessionInfoDelegateFinished(
FWalletConnectSessionInfo SessionInfo);
void OnReceiveWalletconnectPolling(FString jsonevent, FString result);

public:
UWalletConnectTriggerComponent();
Expand Down
3 changes: 3 additions & 0 deletions Metaverse/Source/Metaverse/Public/NPC/CallDynamicContract.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ UCLASS()
class METAVERSE_API ACallDynamicContract : public AHelp {
GENERATED_BODY()

protected:
void Setup();

public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Contract")
UDynamicContractObject *UserDynamicContractObject;
Expand Down
22 changes: 12 additions & 10 deletions Metaverse/Source/Metaverse/Public/NPC/Erc20Transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ struct FWalletSendTXEip155Result;
*/
UCLASS()
class METAVERSE_API AErc20Transfer : public AHelp {
GENERATED_BODY()
GENERATED_BODY()

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called when the game starts or when spawned
virtual void BeginPlay() override;

UFUNCTION()
void OnErc20TransferBeginOverlap(
UPrimitiveComponent *OverlappedComponent, AActor *OtherActor,
UPrimitiveComponent *OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult &SweepResult);
UFUNCTION()
void OnErc20TransferBeginOverlap(UPrimitiveComponent *OverlappedComponent,
AActor *OtherActor,
UPrimitiveComponent *OtherComp,
int32 OtherBodyIndex, bool bFromSweep,
const FHitResult &SweepResult);

private:
UFUNCTION()
void OnWalletconnectErc20TranferFinished(FWalletSendTXEip155Result TxResult);
UFUNCTION()
void
OnWalletconnectErc20TranferFinished(FWalletSendTXEip155Result TxResult);
};
Binary file modified simple/Content/Tutorials/ERC1155/NFTErc1155.umap
Binary file not shown.
Binary file modified simple/Content/Tutorials/ERC1155/WBP_NftErc1155UI.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 3972975

Please sign in to comment.