feat: add an option to read wallet balance at a given height
This commit is contained in:
@@ -1,9 +1,20 @@
|
||||
export function handle(state, action) {
|
||||
export async function handle(state, action) {
|
||||
const balances = state.balances;
|
||||
const canEvolve = state.canEvolve;
|
||||
const input = action.input;
|
||||
const caller = action.caller;
|
||||
|
||||
if (input.function === 'storeBalance') {
|
||||
const target = input.target;
|
||||
const height = SmartWeave.block.height;
|
||||
if (state.wallets.height === undefined) {
|
||||
state.wallets[height] = {};
|
||||
}
|
||||
state.wallets[height][target] = await SmartWeave.arweave.wallets.getBalance(target);
|
||||
|
||||
return { state };
|
||||
}
|
||||
|
||||
if (input.function === 'transfer') {
|
||||
const target = input.target;
|
||||
const qty = input.qty;
|
||||
@@ -34,7 +45,7 @@ export function handle(state, action) {
|
||||
balances[target] = qty;
|
||||
}
|
||||
|
||||
return { state };
|
||||
return {state};
|
||||
}
|
||||
|
||||
if (input.function === 'balance') {
|
||||
@@ -49,7 +60,7 @@ export function handle(state, action) {
|
||||
throw new ContractError('Cannot get balance, target does not exist');
|
||||
}
|
||||
|
||||
return { result: { target, ticker, balance: balances[target] } };
|
||||
return {result: {target, ticker, balance: balances[target]}};
|
||||
}
|
||||
|
||||
if (input.function === 'evolve' && canEvolve) {
|
||||
@@ -59,8 +70,9 @@ export function handle(state, action) {
|
||||
|
||||
state.evolve = input.value;
|
||||
|
||||
return { state };
|
||||
return {state};
|
||||
}
|
||||
|
||||
|
||||
throw new ContractError(`No function supplied or function not recognised: "${input.function}"`);
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
"balances": {
|
||||
"uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M": 10000000,
|
||||
"33F0QHcb22W7LwWR1iRC8Az1ntZG09XQ03YWuw2ABqA": 23111222
|
||||
}
|
||||
},
|
||||
"wallets": {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user