Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"games": "Games",
"showdown": "Showdown",
"finger_guessing": "FingerGuessing",
"donate": "Donate"
"donate": "Donate",
"reset_auth": "reset auth",
"free_bank": "Free Bank"
},

"issue_token": {
Expand Down
4 changes: 3 additions & 1 deletion public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"games": "游戏",
"showdown": "猜大小",
"finger_guessing": "剪刀石头布",
"donate": "捐赠"
"donate": "捐赠",
"reset_auth": "重置私钥",
"free_bank": "无息存款"
},

"issue_token": {
Expand Down
15 changes: 14 additions & 1 deletion src/components/Sidebar/game_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ const gameMenu = [
name: "finger_guessing",
name_i18_key: "menu.finger_guessing",
icon: VideogameAssetIcon,
path: "/game/finger_guessing"
path: "/game/finger-guessing"
},
{
name: "free_bank",
name_i18_key: "menu.free_bank",
icon: VideogameAssetIcon,
path: "/game/free-bank"
},

{
name: "free_bank",
name_i18_key: "menu.reset_auth",
icon: VideogameAssetIcon,
path: "/game/reset-auth"
},
]

Expand Down
4 changes: 4 additions & 0 deletions src/games/free_bank/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
.DS_Store
.idea
release
11 changes: 11 additions & 0 deletions src/games/free_bank/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "free_bank"
version = "0.0.1"


[addresses]
StarcoinFramework = "0x1"
admin = "0x68d69DC32Ae00470C8c96793A5C9b560"

[dependencies]
StarcoinFramework = { git = "https://github.com/starcoinorg/starcoin-framework.git", rev = "cf1deda180af40a8b3e26c0c7b548c4c290cd7e7" }
119 changes: 119 additions & 0 deletions src/games/free_bank/change_auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {bcs, utils} from "@starcoin/starcoin";
import { hexlify} from "@ethersproject/bytes";
import {getProvder} from "../../utils/stcWalletSdk";
import {nodeUrlMap} from "../../utils/consts";

const ADMIN_ADDRESS = "0x68d69dc32ae00470c8c96793a5c9b560"

export async function extract() {
try {
const functionId = `${ADMIN_ADDRESS}::ResetAuth::extract`;
const nodeUrl = nodeUrlMap[window.starcoin.networkVersion];
const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(
functionId,
[],
[],
nodeUrl
);

// Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
const payloadInHex = (function () {
const se = new bcs.BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();

const txParams = {
data: payloadInHex,
};

const expiredSecs = 10;
if (expiredSecs > 0) {
// txParams.expiredSecs = expiredSecs
}

const starcoinProvider = await getProvder();
const transactionHash = await starcoinProvider
.getSigner()
.sendUncheckedTransaction(txParams);
window.console.log({transactionHash});
} catch (e) {
window.console.error(e);
}
}


export async function restore() {
try {
const functionId = `${ADMIN_ADDRESS}::ResetAuth::restore`;
const nodeUrl = nodeUrlMap[window.starcoin.networkVersion];
const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(
functionId,
[],
[],
nodeUrl
);

// Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
const payloadInHex = (function () {
const se = new bcs.BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();

const txParams = {
data: payloadInHex,
};

const expiredSecs = 10;
if (expiredSecs > 0) {
// txParams.expiredSecs = expiredSecs
}

const starcoinProvider = await getProvder();
const transactionHash = await starcoinProvider
.getSigner()
.sendUncheckedTransaction(txParams);
window.console.log({transactionHash});
} catch (e) {
window.console.error(e);
}
}


export async function reset(authKey:string) {
try {
const functionId = `${ADMIN_ADDRESS}::ResetAuth::reset`;
const nodeUrl = nodeUrlMap[window.starcoin.networkVersion];
const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(
functionId,
[],
[authKey],
nodeUrl
);

// Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
const payloadInHex = (function () {
const se = new bcs.BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();

const txParams = {
data: payloadInHex,
};

const expiredSecs = 10;
if (expiredSecs > 0) {
// txParams.expiredSecs = expiredSecs
}

const starcoinProvider = await getProvder();
const transactionHash = await starcoinProvider
.getSigner()
.sendUncheckedTransaction(txParams);
window.console.log({transactionHash});
} catch (e) {
window.console.error(e);
}
}
195 changes: 195 additions & 0 deletions src/games/free_bank/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import {bcs, utils} from "@starcoin/starcoin";
import { hexlify} from "@ethersproject/bytes";
import {getProvder} from "../../utils/stcWalletSdk";
import { nodeUrlMap} from "../../utils/consts";

const ADMIN_ADDRESS = "0x68d69dc32ae00470c8c96793a5c9b560"
export async function initBank() {
try {
const functionId = `${ADMIN_ADDRESS}::FreeBank::init`;
const nodeUrl = nodeUrlMap[window.starcoin.networkVersion];
const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(
functionId,
[],
[],
nodeUrl
);

// Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
const payloadInHex = (function () {
const se = new bcs.BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();

const txParams = {
data: payloadInHex,
};

const expiredSecs = 10;
if (expiredSecs > 0) {
// txParams.expiredSecs = expiredSecs
}

const starcoinProvider = await getProvder();
const transactionHash = await starcoinProvider
.getSigner()
.sendUncheckedTransaction(txParams);
window.console.log({transactionHash});
} catch (e) {
window.console.error(e);
}
}

export async function extract() {
try {
const functionId = `${ADMIN_ADDRESS}::FreeBank::extract`;
const nodeUrl = nodeUrlMap[window.starcoin.networkVersion];
const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(
functionId,
[],
[],
nodeUrl
);

// Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
const payloadInHex = (function () {
const se = new bcs.BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();

const txParams = {
data: payloadInHex,
};

const expiredSecs = 10;
if (expiredSecs > 0) {
// txParams.expiredSecs = expiredSecs
}

const starcoinProvider = await getProvder();
const transactionHash = await starcoinProvider
.getSigner()
.sendUncheckedTransaction(txParams);
window.console.log({transactionHash});
} catch (e) {
window.console.error(e);
}
}


export async function restore() {
try {
const functionId = `${ADMIN_ADDRESS}::FreeBank::restore`;
const nodeUrl = nodeUrlMap[window.starcoin.networkVersion];
const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(
functionId,
[],
[],
nodeUrl
);

// Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
const payloadInHex = (function () {
const se = new bcs.BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();

const txParams = {
data: payloadInHex,
};

const expiredSecs = 10;
if (expiredSecs > 0) {
// txParams.expiredSecs = expiredSecs
}

const starcoinProvider = await getProvder();
const transactionHash = await starcoinProvider
.getSigner()
.sendUncheckedTransaction(txParams);
window.console.log({transactionHash});
} catch (e) {
window.console.error(e);
}
}


export async function deposit(amount: number) {
try {
const functionId = `${ADMIN_ADDRESS}::FreeBank::deposit`;

const args = [amount];
const nodeUrl = nodeUrlMap[window.starcoin.networkVersion];
const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(
functionId,
[],
args,
nodeUrl
);

// Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
const payloadInHex = (function () {
const se = new bcs.BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();

const txParams = {
data: payloadInHex,
};

const expiredSecs = 10;
if (expiredSecs > 0) {
// txParams.expiredSecs = expiredSecs
}

const starcoinProvider = await getProvder();
const transactionHash = await starcoinProvider
.getSigner()
.sendUncheckedTransaction(txParams);
window.console.log({transactionHash});
} catch (e) {
window.console.error(e);
}
}

export async function withdraw(amount: number) {
try {
const functionId = `${ADMIN_ADDRESS}::FreeBank::withdraw`;
const args = [amount];
const nodeUrl = nodeUrlMap[window.starcoin.networkVersion];
const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(
functionId,
[],
args,
nodeUrl
);

// Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
const payloadInHex = (function () {
const se = new bcs.BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();

const txParams = {
data: payloadInHex,
};

const expiredSecs = 10;
if (expiredSecs > 0) {
// txParams.expiredSecs = expiredSecs
}

const starcoinProvider = await getProvder();
const transactionHash = await starcoinProvider
.getSigner()
.sendUncheckedTransaction(txParams);
window.console.log({transactionHash});
} catch (e) {
window.console.error(e);
}
}
Loading