增加一个调用wallet方法的通用方法

This commit is contained in:
cebgcontract 2022-07-13 15:29:31 +08:00
parent c4c56cd7bc
commit cd31627c87
4 changed files with 24 additions and 10 deletions

View File

@ -17,7 +17,6 @@ NS_CC_BEGIN
cocos2d::Application *g_app = nullptr; cocos2d::Application *g_app = nullptr;
JcWallet *JcWallet::_instance = nullptr; JcWallet *JcWallet::_instance = nullptr;
static std::string result;
bool _isStarted = false; bool _isStarted = false;
JcWallet::JcWallet() { JcWallet::JcWallet() {
@ -46,8 +45,10 @@ NS_CC_BEGIN
char* JcWallet::initWallet() { char* JcWallet::initWallet() {
se::Value value; se::Value value;
jsb_run_code("jc.wallet.currentAccount().address", &value); jsb_run_code("jc.wallet.currentAccount().address", &value);
result = value.toString(); static std::string result = value.toString();
WalletEvent::Emit("wallet_inited", "{}"); WalletEvent::Emit("wallet_inited", "{1}");
WalletEvent::Emit("wallet_inited", "{2}");
WalletEvent::Emit("wallet_inited", "{3}");
return const_cast<char*>(result.c_str()); return const_cast<char*>(result.c_str());
} }
@ -57,14 +58,14 @@ NS_CC_BEGIN
std::string jsCode = "jc.wallet.loginSign('" + nonce + "','" + tips + "')"; std::string jsCode = "jc.wallet.loginSign('" + nonce + "','" + tips + "')";
se::Value value; se::Value value;
jsb_run_code(jsCode, &value); jsb_run_code(jsCode, &value);
result = value.toString(); static std::string result = value.toString();
return const_cast<char*>(result.c_str()); return const_cast<char*>(result.c_str());
} }
char* JcWallet::createAccount() { char* JcWallet::createAccount() {
se::Value value; se::Value value;
jsb_run_code("jc.wallet.createAccount()", &value); jsb_run_code("jc.wallet.createAccount()", &value);
result = value.toString(); static std::string result = value.toString();
return const_cast<char*>(result.c_str()); return const_cast<char*>(result.c_str());
} }
@ -73,10 +74,19 @@ NS_CC_BEGIN
std::string jsCode = "jc.wallet.importAccount('" + key + "')"; std::string jsCode = "jc.wallet.importAccount('" + key + "')";
se::Value value; se::Value value;
jsb_run_code(jsCode, &value); jsb_run_code(jsCode, &value);
result = value.toString(); static std::string result = value.toString();
return const_cast<char*>(result.c_str()); return const_cast<char*>(result.c_str());
} }
char* runMethod(const char *methodName, const char *params) {
std::string methodStr(methodName);
std::string paramsStr(params);
std::string jsCode = "jc.wallet."+methodStr+"('" + paramsStr + "')";
se::Value value;
jsb_run_code(jsCode, &value);
static std::string result = value.toString();
return const_cast<char*>(result.c_str());
}
extern "C" extern "C"
{ {
@ -93,6 +103,9 @@ NS_CC_BEGIN
char* importAccount(const char *privateKey) { char* importAccount(const char *privateKey) {
return JcWallet::getInstance()->importAccount(privateKey); return JcWallet::getInstance()->importAccount(privateKey);
} }
char* runWalletMethod(const char *methodName, const char *params) {
return JcWallet::getInstance()->runMethod(methodName, params);
}
} }
NS_CC_END NS_CC_END

View File

@ -11,6 +11,7 @@ public:
char* signLogin(const char *nonceChar, const char *tipChar); char* signLogin(const char *nonceChar, const char *tipChar);
char* createAccount(); char* createAccount();
char* importAccount(const char *privateKey); char* importAccount(const char *privateKey);
char* runMethod(const char *methodName, const char *params);
private: private:
static JcWallet* _instance; static JcWallet* _instance;
}; };

View File

@ -30,8 +30,8 @@
filePath = "Classes_cocos/JcWallet.cpp" filePath = "Classes_cocos/JcWallet.cpp"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "55" startingLineNumber = "56"
endingLineNumber = "55" endingLineNumber = "56"
landmarkName = "JcWallet::signLogin(nonceChar, tipChar)" landmarkName = "JcWallet::signLogin(nonceChar, tipChar)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
@ -46,8 +46,8 @@
filePath = "Classes_cocos/JcWallet.cpp" filePath = "Classes_cocos/JcWallet.cpp"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "65" startingLineNumber = "66"
endingLineNumber = "65" endingLineNumber = "66"
landmarkName = "JcWallet::createAccount()" landmarkName = "JcWallet::createAccount()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>