cocos_android/js/main.js
2022-07-21 10:24:11 +08:00

77 lines
2.0 KiB
JavaScript

console.log('>>hi tiny wallet3')
function initWallet(password) {
try {
if ( !window.jc || !jc.wwallet ) {
var wallet = new jcwallet.default(password);
}
let address = jc.wallet.currentAccount().address
return JSON.stringify({errcode: 0, data: address});
} catch(err) {
return JSON.stringify({errcode: 1, errmsg: err});
}
}
function currentAccount() {
try {
let address = jc.wallet.currentAccount().address
return JSON.stringify({errcode: 0, data: address});
} catch(err) {
return JSON.stringify({errcode: 1, errmsg: err});
}
}
function loginSign(nonce, tips) {
try {
let result = jc.wallet.loginSign(nonce, tips);
return JSON.stringify({errcode: 0, data: result});
} catch(err) {
return JSON.stringify({errcode: 1, errmsg: err});
}
}
function createAccount() {
try {
let result = jc.wallet.createAccount();
return JSON.stringify({errcode: 0, data: result});
} catch(err) {
return JSON.stringify({errcode: 1, errmsg: err});
}
}
function importAccount(privateKey) {
try {
let address = jc.wallet.importAccount(privateKey)
return JSON.stringify({errcode: 0, data: address});
} catch(err) {
return JSON.stringify({errcode: 1, errmsg: err});
}
}
function selectAccount(address) {
try {
let result = jc.wallet.selectAccount(address);
return JSON.stringify({errcode: 0, data: result});
} catch(err) {
return JSON.stringify({errcode: 1, errmsg: err});
}
}
function getBalance(address) {
try {
let result = jc.wallet.getBalance(address);
return JSON.stringify({errcode: 0, data: result});
} catch(err) {
return JSON.stringify({errcode: 1, errmsg: err});
}
}
function sendEth(to, amount) {
try {
let result = jc.wallet.sendEth(to, amount);
return JSON.stringify({errcode: 0, data: result});
} catch(err) {
return JSON.stringify({errcode: 1, errmsg: err});
}
}