Skip to content

Commit 60f8491

Browse files
committed
update
1 parent 4251f63 commit 60f8491

File tree

6 files changed

+46
-76
lines changed

6 files changed

+46
-76
lines changed

src/chain-libs/chain-impl-mockchain/src/accounting/account/spending.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ mod tests {
294294
}
295295

296296
#[test]
297-
#[should_panic]
298297
pub fn spending_counter_increasing_wrong_lane() {
299298
let mut sc_increasing = SpendingCounterIncreasing::default();
300299
let incorrect_sc = SpendingCounter::new(SpendingCounterIncreasing::LANES, 1).unwrap();

src/chain-wallet-libs/bindings/wallet-core/src/tx_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct TxBuilder<P: Payload> {
1313
builder: wallet::TransactionBuilder<P>,
1414
}
1515

16-
impl<'settings, P: Payload> TxBuilder<P> {
16+
impl<P: Payload> TxBuilder<P> {
1717
pub fn new(settings: Settings, valid_until: BlockDate, payload: P) -> Self {
1818
let builder = wallet::TransactionBuilder::new(settings, payload, valid_until);
1919
Self { builder }

src/chain-wallet-libs/bindings/wallet-wasm-js/js-test/test/vote_cast.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ describe("vote cast certificate tests", function () {
1919
"hex"
2020
),
2121
2,
22-
true,
2322
8
2423
);
25-
let vote = proposal.vote(1, 1, new wallet.BlockDate(0, 1), 0);
24+
let vote = new wallet.Vote(proposal, 0, new wallet.BlockDate(0, 1), 1, 1);
2625
let fragments = wallet.signVotes([vote], settings, private_key);
2726
assert(fragments.length == 1);
2827
});
@@ -37,14 +36,13 @@ describe("vote cast certificate tests", function () {
3736
"hex"
3837
),
3938
4,
40-
true,
4139
8,
4240
Buffer.from(
4341
"bed88887abe0a84f64691fe0bdfa3daf1a6cd697a13f07ae07588910ce39c927",
4442
"hex"
4543
)
4644
);
47-
let vote = proposal.vote(1, 1, new wallet.BlockDate(0, 1), 0);
45+
let vote = new wallet.Vote(proposal, 0, new wallet.BlockDate(0, 1), 1, 1);
4846
let fragments = wallet.signVotes([vote], settings, private_key);
4947
assert(fragments.length == 1);
5048
});

src/chain-wallet-libs/bindings/wallet-wasm-js/js/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export class Settings {
3535
*/
3636
export class Vote {
3737
voteCast: wallet_wasm.VoteCast;
38+
spendingCounter: number;
39+
spendingCounterLane: number;
40+
validUntil: BlockDate;
3841

3942
/**
4043
* Constructs public wallet-wasm-js VoteCast vote

src/chain-wallet-libs/bindings/wallet-wasm-js/js/index.js

Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -21,98 +21,68 @@ module.exports.Settings = Settings;
2121

2222
class Vote {
2323
constructor(
24-
spendingCounter,
25-
spendingCounterLane,
26-
validUntil,
27-
votePlan,
28-
proposalIndex,
24+
proposal,
2925
choice,
30-
options,
31-
publicKey
26+
expiration,
27+
spendingCounter,
28+
spendingCounterLane
3229
) {
30+
this.proposal = proposal;
31+
this.choice = choice;
32+
this.expiration = expiration;
3333
this.spendingCounter = spendingCounter;
3434
this.spendingCounterLane = spendingCounterLane;
35-
this.validUntil = validUntil;
36-
if (options != undefined && publicKey != undefined) {
37-
let payload = wasm.Payload.new_private(
38-
wasm.VotePlanId.from_bytes(votePlan),
39-
options,
40-
choice,
41-
publicKey
42-
);
43-
this.voteCast = wasm.VoteCast.new(
44-
wasm.VotePlanId.from_bytes(votePlan),
45-
proposalIndex,
46-
payload
47-
);
48-
} else {
49-
let payload = wasm.Payload.new_public(choice);
50-
this.voteCast = wasm.VoteCast.new(
51-
wasm.VotePlanId.from_bytes(votePlan),
52-
proposalIndex,
53-
payload
54-
);
55-
}
5635
}
5736
}
5837
module.exports.Vote = Vote;
5938

6039
class Proposal {
61-
constructor(
62-
votePlan,
63-
voteOptions,
64-
votePublic,
65-
proposalIndex,
66-
committee_public_key
67-
) {
40+
constructor(votePlan, voteOptions, proposalIndex, voteEncKey) {
6841
this.votePlan = votePlan;
6942
this.voteOptions = voteOptions;
70-
this.votePublic = votePublic;
7143
this.proposalIndex = proposalIndex;
72-
this.committee_public_key = committee_public_key;
73-
}
74-
75-
vote(spendingCounter, spendingCounterLane, validUntil, choice) {
76-
if (this.votePublic) {
77-
return new Vote(
78-
spendingCounter,
79-
spendingCounterLane,
80-
validUntil,
81-
this.votePlan,
82-
this.proposalIndex,
83-
choice
84-
);
85-
} else {
86-
return new Vote(
87-
spendingCounter,
88-
spendingCounterLane,
89-
validUntil,
90-
this.votePlan,
91-
this.proposalIndex,
92-
choice,
93-
this.voteOptions,
94-
this.committee_public_key
95-
);
96-
}
44+
this.voteEncKey = voteEncKey;
9745
}
9846
}
9947
module.exports.Proposal = Proposal;
10048

10149
function signVotes(votes, settings, privateKey) {
10250
let fragments = [];
10351
for (let i = 0; i < votes.length; i++) {
52+
let vote = votes[i];
53+
let voteCast;
54+
if (
55+
vote.proposal.options != undefined &&
56+
vote.proposal.voteEncKey != undefined
57+
) {
58+
let payload = wasm.Payload.new_private(
59+
wasm.VotePlanId.from_bytes(vote.proposal.votePlan),
60+
vote.proposal.options,
61+
vote.choice,
62+
vote.proposal.voteEncKey
63+
);
64+
voteCast = wasm.VoteCast.new(
65+
wasm.VotePlanId.from_bytes(vote.proposal.votePlan),
66+
vote.proposal.proposalIndex,
67+
payload
68+
);
69+
} else {
70+
let payload = wasm.Payload.new_public(vote.choice);
71+
voteCast = wasm.VoteCast.new(
72+
wasm.VotePlanId.from_bytes(vote.proposal.votePlan),
73+
vote.proposal.proposalIndex,
74+
payload
75+
);
76+
}
77+
10478
let builder = wasm.VoteCastTxBuilder.new(
10579
settings.settings,
106-
votes[i].validUntil.epoch,
107-
votes[i].validUntil.slot,
108-
votes[i].voteCast
80+
vote.expiration.epoch,
81+
vote.expiration.slot,
82+
voteCast
10983
);
11084
let fragment = builder
111-
.build_tx(
112-
privateKey,
113-
votes[i].spendingCounter,
114-
votes[i].spendingCounterLane
115-
)
85+
.build_tx(privateKey, vote.spendingCounter, vote.spendingCounterLane)
11686
.finalize_tx();
11787
fragments.push(fragment);
11888
}

src/chain-wallet-libs/bindings/wallet-wasm-js/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl VoteCastTxBuilder {
8080
/// Finish step of building VoteCast fragment
8181
pub fn finalize_tx(self) -> Result<Fragment, JsValue> {
8282
self.0
83-
.finalize_tx((), |tx| FragmentLib::VoteCast(tx))
83+
.finalize_tx((), FragmentLib::VoteCast)
8484
.map_err(|e| JsValue::from(e.to_string()))
8585
.map(Fragment)
8686
}

0 commit comments

Comments
 (0)