Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: missing dynamic contract (fix #226) #230

Merged
merged 1 commit into from
Jan 5, 2023
Merged

Problem: missing dynamic contract (fix #226) #230

merged 1 commit into from
Jan 5, 2023

Conversation

leejw51crypto
Copy link
Collaborator

Solution: add dynamic contract

@leejw51crypto
Copy link
Collaborator Author

files under CronosPlayUnreal can be reviewed

other files are automatically generated

@leejw51crypto
Copy link
Collaborator Author

checking ci issues

@leejw51crypto
Copy link
Collaborator Author

investigating unreal error

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Dec 13, 2022

@damoncro fixed in play-cpp-sdk, will upgrade play-cpp-sdk shortly

@leejw51crypto
Copy link
Collaborator Author

for linux, back to use clang 10

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few unrelated linter errors (/Source/CronosPlayUnreal/Private/DefiWalletCoreActor.cpp:20:13 [modernize-use-trailing-return-type] use a trailing return type for this function; /Source/CronosPlayUnreal/Private/DefiWalletCoreActor.cpp:28:21 [cppcoreguidelines-init-variables] variable 'ret' is not initialized etc.)

--

besides that, can the API in Unreal be split into contract object construction (to be done once by the developer) and function calling (that could be done multiple times) to match C++ bindings?

Comment on lines 1930 to 1936
void ADefiWalletCoreActor::SendDynamicContract(
FString contractAddress, int32 walletindex, FString abiJson,
FString functionName, FString functionArgs,
FDynamicContractSendDelegate Out) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these all be under defiwalletcoreactor? or could there be a "contract actor" or something like that that one will initialize once with the common params (contract address, abijson, rpc address) and then just call a function on it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's possible. i'll refactor

* @param walletindex wallet index which starts from 0
* @param abiJson abi json
* @param functionName function name
* @param functionArgs function args injson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the function args, it'll be good to give an example, because the format is not obvious just from the description... maybe using doxygen's \code ... \endcode command?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i'll add an example , so that user can refer to it

@leejw51crypto
Copy link
Collaborator Author

ok, working on the feedback

@leejw51crypto leejw51crypto marked this pull request as draft December 13, 2022 08:50
@leejw51crypto
Copy link
Collaborator Author

a few unrelated linter errors (/Source/CronosPlayUnreal/Private/DefiWalletCoreActor.cpp:20:13 [modernize-use-trailing-return-type] use a trailing return type for this function; /Source/CronosPlayUnreal/Private/DefiWalletCoreActor.cpp:28:21 [cppcoreguidelines-init-variables] variable 'ret' is not initialized etc.)

--

besides that, can the API in Unreal be split into contract object construction (to be done once by the developer) and function calling (that could be done multiple times) to match C++ bindings?

yes, that's possible.
i'll separate DynamicContract as object, can be called multiple times

@leejw51crypto
Copy link
Collaborator Author

working now~

@leejw51crypto
Copy link
Collaborator Author

  • added DynamicContract actor,
  • ported send, encode, call to this class
  • testing now

@leejw51crypto leejw51crypto force-pushed the feature/226a branch 2 times, most recently from b89c127 to c8804ff Compare December 14, 2022 11:35
@leejw51crypto
Copy link
Collaborator Author

rebased

@leejw51crypto leejw51crypto force-pushed the feature/226a branch 2 times, most recently from df622d6 to 24b48a8 Compare December 14, 2022 11:41
@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Dec 14, 2022

uninitialize error : using default constructor doesn't work, applied NOLINT

fixed trailing return warning

@leejw51crypto leejw51crypto marked this pull request as ready for review December 14, 2022 15:02
@leejw51crypto leejw51crypto marked this pull request as draft December 15, 2022 01:32
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the actor be instantiated multiple times (if one wanted to use different dynamic contracts at the same time)?

@@ -0,0 +1,241 @@
// Fill out your copyright notice in the Description page of Project Settings.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this comment should be changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i'll remove it

Comment on lines 7 to 9
// Set this actor to call Tick() every frame. You can turn this off to
// improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be off?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

// improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
defiWallet = NULL;
_coreContract = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it will only allow one contract globally? or can one instantiate multiple actors that have different contracts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be multiple

@@ -0,0 +1,161 @@
// Fill out your copyright notice in the Description page of Project Settings.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably to be changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i'll remove it

/**
* @param cronosrpc cronos rpc server endpoint
* @param contractaddress contract address
* @param abijson contract abi json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it should specify that it should be the abi json text/content... someone may be confused and put e.g. a file path to abi json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 70 to 73
* simple json example: Address, String
* [{"Address":{"data":"0x00"}},{"Str":{"data":"my"}}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for these examples, maybe it'll be also good to write Solidity function signature, so it's more obvious what t hat sample corresponds?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@damoncro
Copy link
Contributor

CI does not run.

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Dec 15, 2022

working on feedback, and will check ci

@leejw51crypto leejw51crypto force-pushed the feature/226a branch 2 times, most recently from 19ea96d to 5d1eb5b Compare December 16, 2022 05:55
@leejw51crypto
Copy link
Collaborator Author

updated changelog

@damoncro
Copy link
Contributor

damoncro commented Dec 16, 2022

Any reason to create a new Actor instead of putting it into DefiWalletCoreActor? Common things like cronosrpc can be shared inside DefiWalletCoreActor.

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Dec 19, 2022

  • dynamic contract can be created and destroyed easily.
  • and dynamic contract has its own context, can call functions multiple times.
  • and it's connected by smart pointer, so signing is done from defi-wallet-core.
  • with non-modifying calls, defi-wallet-core is not necessary

@damoncro
Copy link
Contributor

  • dynamic contract can be created and destroyed easily.
  • and dynamic contract has its own context, can call functions multiple times.
  • and it's connected by smart pointer, so signing is done from defi-wallet-core.
  • with non-modifying calls, defi-wallet-core is not necessary

How about cronosrpc?

@leejw51crypto
Copy link
Collaborator Author

working on it

@leejw51crypto leejw51crypto force-pushed the feature/226a branch 4 times, most recently from 58148b9 to 38eca15 Compare January 3, 2023 08:52
@leejw51crypto leejw51crypto requested a review from damoncro January 3, 2023 08:53
@leejw51crypto
Copy link
Collaborator Author

ready to review

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one main question is why *_coreContract is public? I guess *defiWallet needs to be public, so that it can be set/accessed from a blueprint? or could it be private and have blueprint getter/setter?

FString abijson, bool &success,
FString &output_message) {
UDynamicContractObject *ret = NewObject<UDynamicContractObject>();
ret->defiWallet = this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok for ret->defiWallet to be accessed concurrently?

Copy link
Collaborator Author

@leejw51crypto leejw51crypto Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw pointer is not protected, but defiWallet is marked as "UPROPERTY" , and managed by unreal garbage collector.

and like unity3d, for unreal engine,engine related apis are all in the single thread(game thread), so concurrency safe. only ue4 engine apis can be called in that thread.

rendering, networking are in other threads

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_coreContract can be private, i'll change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm double checking with unreal engine document

Comment on lines 26 to 29
// restored back
rust::cxxbridge1::Box<org::defi_wallet_core::EthContract> tmpwallet =
rust::cxxbridge1::Box<org::defi_wallet_core::EthContract>::from_raw(
_coreContract);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed? for deallocating that contract object in Rust?
nit: var name perhaps can be tmpcontract?

Copy link
Collaborator Author

@leejw51crypto leejw51crypto Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c++ pointer is earned by "into_raw" , so give ownership back to rust box, remove elegantly.

i'll change the name

#include "PlayCppSdkLibrary/Include/defi-wallet-core-cpp/src/ethereum.rs.h"
#include "DynamicContractObject.generated.h"

using namespace std;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some linter warnings:

variable 'namespace' is non-const and globally accessible, consider making it const

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i'll check linting errors

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CronosPlayUnreal")
ADefiWalletCoreActor *defiWallet;

org::defi_wallet_core::EthContract *_coreContract;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why to have this internal field in public: and not private: ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_coreContract can be private, i'll change

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Jan 4, 2023

fixed c++ linting errors

@leejw51crypto
Copy link
Collaborator Author

leejw51crypto commented Jan 5, 2023

checked UPROERTY and raw pointer
ref:
https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Objects/Optimizations/

document is a little ambiguous

@leejw51crypto leejw51crypto marked this pull request as draft January 5, 2023 01:06
@leejw51crypto leejw51crypto marked this pull request as ready for review January 5, 2023 01:30
@damoncro
Copy link
Contributor

damoncro commented Jan 5, 2023

Please update CHANGELOG.md.

@leejw51crypto
Copy link
Collaborator Author

ok

update play-cpp-sdk

ok

add encode

add call

adding send

send working

add read json

add comment

format back

format

rebase

specify ubuntu version

use ubuntu-20.04

fix signing

upgrade play-cpp-sdk

compiles

send ok

read json as static

add comment

add json example

add example

fix typo

restore

Problem: missing dynamic contract (fix #226)

update play-cpp-sdk

ok

add encode

add call

adding send

send working

add read json

add comment

format back

format

rebase

specify ubuntu version

use ubuntu-20.04

fix signing

upgrade play-cpp-sdk

compiles

send ok

read json as static

add comment

add json example

add example

fix typo

restore

check lint

update play-cpp-sdk

change header

not run in every frame

json string clear comment

add function sig

add changelog

add dynamic-contract uobject

works

add log

add log

remove contract actor

add comment

add comment

add json example

add json comment

make private

change variable name

fix lint

nolint

changelog update
@tomtau tomtau merged commit 3c54ad5 into main Jan 5, 2023
@tomtau tomtau deleted the feature/226a branch February 9, 2023 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants