Skip to content

Commit

Permalink
update contracts to not require sender sig on reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
45930 committed Nov 30, 2023
1 parent 876a90b commit e7cc8e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
16 changes: 6 additions & 10 deletions src/TokenElection/BaseTokenElection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export class Ballot extends Struct({
}) { }

export class VoteAction extends Struct({
ballot: Ballot,
sender: PublicKey,
amount: UInt64
ballot: Ballot
}) { }

export class TokenElection extends SmartContract {
Expand Down Expand Up @@ -61,11 +59,13 @@ export class TokenElection extends SmartContract {
voteSum = voteSum.add(unpackedVote2[i]);
}
voteSum.assertEquals(amount); // sum of votes must equal asserted amount (can vote for multiple options)
this.reducer.dispatch({
ballot: vote,
sender: this.sender,
this.token.burn({
address: this.sender,
amount: UInt64.from(amount)
});
this.reducer.dispatch({
ballot: vote
});
}

@method
Expand All @@ -92,10 +92,6 @@ export class TokenElection extends SmartContract {
for (let i = 0; i < PartialBallot.l; i++) {
unpackedState2[i] = unpackedState2[i].add(unpackedAction2[i])
}
this.token.burn({
address: _action.sender,
amount: UInt64.from(_action.amount)
});
return {
partial1: PartialBallot.fromUInt32s(unpackedState1).packed,
partial2: PartialBallot.fromUInt32s(unpackedState2).packed
Expand Down
16 changes: 6 additions & 10 deletions src/TokenElection/WhitelistTokenElection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export class Ballot extends Struct({
}) { }

export class VoteAction extends Struct({
ballot: Ballot,
sender: PublicKey,
amount: UInt64
ballot: Ballot
}) { }

export class WhitelistTokenElection extends SmartContract {
Expand Down Expand Up @@ -89,11 +87,13 @@ export class WhitelistTokenElection extends SmartContract {
voteSum = voteSum.add(unpackedVote2[i]);
}
voteSum.assertEquals(amount); // sum of votes must equal asserted amount (can vote for multiple options)
this.reducer.dispatch({
ballot: vote,
sender: this.sender,
this.token.burn({
address: this.sender,
amount: UInt64.from(amount)
});
this.reducer.dispatch({
ballot: vote
});
}

@method
Expand All @@ -120,10 +120,6 @@ export class WhitelistTokenElection extends SmartContract {
for (let i = 0; i < PartialBallot.l; i++) {
unpackedState2[i] = unpackedState2[i].add(unpackedAction2[i])
}
this.token.burn({
address: _action.sender,
amount: UInt64.from(_action.amount)
});
return {
partial1: PartialBallot.fromUInt32s(unpackedState1).packed,
partial2: PartialBallot.fromUInt32s(unpackedState2).packed
Expand Down

0 comments on commit e7cc8e5

Please sign in to comment.