Skip to content

Commit

Permalink
assert spender is caller
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof committed Jul 15, 2024
1 parent 8c0eef4 commit 1224849
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 2 additions & 0 deletions smart-contract/assembly/contracts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ export function startScheduleSendFT(binaryArgs: StaticArray<u8>): void {
const schedule = args
.nextSerializable<Schedule>()
.expect('Schedule is missing or invalid');
assert(Context.caller() === new Address(schedule.spender), 'Unauthorized');
checkAllowance(
schedule.tokenAddress,
schedule.spender,
// @ts-ignore
schedule.amount * u256.fromU64(schedule.occurrences), // TODO: use SafeMathU256
);
scheduleAllSendFT(schedule);
Expand Down
5 changes: 1 addition & 4 deletions smart-contract/assembly/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,13 @@ const schedulesPrefix = 'SCHEDULE';
export const idCounterKey = stringToBytes('C');

function getIdCounter(): u64 {
if (!Storage.has(idCounterKey)) {
return 0;
}
return bytesToU64(Storage.get(idCounterKey));
}

function incrementIdCounter(): u64 {
const counter = getIdCounter();
const inc = counter + 1;
Storage.set(idCounterKey, u64ToBytes(counter + 1));
Storage.set(idCounterKey, u64ToBytes(inc));
return inc;
}

Expand Down

0 comments on commit 1224849

Please sign in to comment.