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

add nonce check #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions example/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ lazy_static::lazy_static! {
pub struct Transaction {
pub command: u64,
pub objindex: usize,
pub nonce: u64,
pub data: Vec<u64>,
}

Expand All @@ -313,8 +314,9 @@ impl Transaction {
}
}
pub fn decode(params: [u64; 4]) -> Self {
let command = (params[0] >> 32) & 0xff;
let objindex = (params[0] & 0xff) as usize;
let command = params[0] & 0xff;
let objindex = ((params[0] >> 8) & 0xff) as usize;
let nonce = params[0] >> 16;
let mut data = vec![];
if command == WITHDRAW {
data = vec![0, params[1], params[2], params[3]] // address of withdraw
Expand All @@ -328,6 +330,7 @@ impl Transaction {
Transaction {
command,
objindex,
nonce,
data,
}
}
Expand All @@ -347,6 +350,7 @@ impl Transaction {
match player.as_mut() {
None => ERROR_PLAYER_NOT_EXIST,
Some(player) => {
player.check_and_inc_nonce(self.nonce);
let objindex = player.data.objects.len();
player.data.objects.push(0);
let mid = self.data[0];
Expand All @@ -367,6 +371,8 @@ impl Transaction {
match player.as_mut() {
None => ERROR_PLAYER_ALREADY_EXIST,
Some(player) => {
player.check_and_inc_nonce(self.nonce);
player.store();
let oid = player.get_obj_id(self.objindex);
let counter = QUEUE.0.borrow().counter;
let data = &self.data;
Expand All @@ -386,6 +392,7 @@ impl Transaction {
match player.as_mut() {
None => ERROR_PLAYER_NOT_EXIST,
Some(player) => {
player.check_and_inc_nonce(self.nonce);
if let Some(treasure) = player.data.local.0.last_mut() {
let withdraw = WithdrawInfo::new(
0,
Expand All @@ -412,6 +419,7 @@ impl Transaction {
match player.as_mut() {
None => {
let mut player = AutomataPlayer::new_from_pid([self.data[0], self.data[1]]);
player.check_and_inc_nonce(self.nonce);
if let Some (treasure) = player.data.local.0.last_mut() {
*treasure += self.data[2] as i64;
player.store();
Expand All @@ -420,6 +428,7 @@ impl Transaction {
}
},
Some(player) => {
player.check_and_inc_nonce(self.nonce);
if let Some(treasure) = player.data.local.0.last_mut() {
*treasure += self.data[2] as i64;
let t = player.data.local.0.last().unwrap();
Expand Down
4 changes: 3 additions & 1 deletion ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified ts/src/application/application_bg.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions ts/src/bootstrap/bootstrap_bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
};

export function __wbg_updateleaf_583e7300fc05dcb2(arg0, arg1, arg2, arg3, arg4) {
export function __wbg_updateleaf_c52d6903ac400a66(arg0, arg1, arg2, arg3, arg4) {
var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
var v1 = getArrayU8FromWasm0(arg3, arg4).slice();
Expand All @@ -233,21 +233,21 @@ export function __wbg_updateleaf_583e7300fc05dcb2(arg0, arg1, arg2, arg3, arg4)
return addHeapObject(ret);
};

export function __wbg_getleaf_24c775a6a2aa4383(arg0, arg1, arg2) {
export function __wbg_getleaf_dc1011d3abd689e9(arg0, arg1, arg2) {
var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
const ret = get_leaf(v0, BigInt.asUintN(64, arg2));
return addHeapObject(ret);
};

export function __wbg_getrecord_4c730ffdc5ac97a0(arg0, arg1) {
export function __wbg_getrecord_9b375b736bbeb572(arg0, arg1) {
var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
const ret = get_record(v0);
return addHeapObject(ret);
};

export function __wbg_updaterecord_9efc2e1d014d3f6a(arg0, arg1, arg2, arg3) {
export function __wbg_updaterecord_0ea13efa10ca9772(arg0, arg1, arg2, arg3) {
var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
var v1 = getArrayU64FromWasm0(arg2, arg3).slice();
Expand Down
Binary file modified ts/src/bootstrap/bootstrap_bg.wasm
Binary file not shown.