62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
#include "JcWallet.h"
|
|
#include <string>
|
|
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
|
#include "cocos/scripting/js-bindings/manual/jsb_global.h"
|
|
#include "scripting/js-bindings/event/EventDispatcher.h"
|
|
#include "platform/CCApplication.h"
|
|
|
|
cocos2d::Application *cocos_android_app_init(int width, int height);
|
|
|
|
using namespace cocos2d;
|
|
NS_CC_BEGIN
|
|
|
|
cocos2d::Application *g_app = nullptr;
|
|
JcWallet *JcWallet::_instance = nullptr;
|
|
|
|
JcWallet::JcWallet() {
|
|
JcWallet::_instance = this;
|
|
}
|
|
|
|
void JcWallet::initEnv() {
|
|
g_app = cocos_android_app_init(1, 1);
|
|
se::ScriptEngine *se = se::ScriptEngine::getInstance();
|
|
EventDispatcher::init();
|
|
g_app->start();
|
|
}
|
|
|
|
JcWallet::~JcWallet() {
|
|
EventDispatcher::destroy();
|
|
se::ScriptEngine::destroyInstance();
|
|
JcWallet::_instance = nullptr;
|
|
}
|
|
|
|
char* JcWallet::initWallet() {
|
|
se::Value rval;
|
|
jsb_run_code("jc.wallet.currentAccount().address", &rval);
|
|
char* result = const_cast<char*>(rval.toString().c_str());
|
|
return result;
|
|
}
|
|
|
|
char* JcWallet::signLogin(const char *nonceChar, const char *tipChar) {
|
|
se::Value rval;
|
|
std::string nonce(nonceChar);
|
|
std::string tips(tipChar);
|
|
std::string jsCode = "jc.wallet.loginSign('" + nonce + "','" + tips + "')";
|
|
jsb_run_code(jsCode, &rval);
|
|
char* result = const_cast<char*>(rval.toString().c_str());
|
|
return result;
|
|
}
|
|
|
|
|
|
extern "C"
|
|
{
|
|
char* initWallet() {
|
|
JcWallet::getInstance()->initEnv();
|
|
return JcWallet::getInstance()->initWallet();
|
|
}
|
|
char* signLogin(const char *nonceChar, const char *tipChar) {
|
|
return JcWallet::getInstance()->signLogin(nonceChar, tipChar);
|
|
}
|
|
}
|
|
|
|
NS_CC_END |