Skip to content

Commit 9b7df6a

Browse files
committed
update
1 parent 60f8491 commit 9b7df6a

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

src/chain-wallet-libs/bindings/wallet-wasm-js/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ wasm-bindgen = "0.2"
3131
js-sys = "0.3.40"
3232
bech32 = "0.7.2"
3333
serde_json = "1.0"
34+
hex = "0.4.2"
3435

3536
# The `console_error_panic_hook` crate provides better debugging of panics by
3637
# logging them with `console.error`. This is great for development, but requires
@@ -45,4 +46,3 @@ clear_on_drop = {version = "0.2", features = ["no_cc"]}
4546

4647
[dev-dependencies]
4748
wasm-bindgen-test = "0.3"
48-
hex = "0.4.2"

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
var assert = require("assert");
22

3-
const private_key = Buffer.from(
4-
"c86596c2d1208885db1fe3658406aa0f7cc7b8e13c362fe46a6db277fc5064583e487588c98a6c36e2e7445c0add36f83f171cb5ccfd815509d19cd38ecb0af3",
5-
"hex"
6-
);
3+
const private_key =
4+
"c86596c2d1208885db1fe3658406aa0f7cc7b8e13c362fe46a6db277fc5064583e487588c98a6c36e2e7445c0add36f83f171cb5ccfd815509d19cd38ecb0af3";
75

86
const settings_json =
97
'{"fees":{"constant":10,"coefficient":2,"certificate":100},"discrimination":"production","block0_initial_hash":{"hash":"baf6b54817cf2a3e865f432c3922d28ac5be641e66662c66d445f141e409183e"},"block0_date":1586637936,"slot_duration":20,"time_era":{"epoch_start":0,"slot_start":0,"slots_per_epoch":180},"transaction_max_expiry_epochs":1}';
@@ -14,10 +12,7 @@ describe("vote cast certificate tests", function () {
1412

1513
let settings = new wallet.Settings(settings_json);
1614
let proposal = new wallet.Proposal(
17-
Buffer.from(
18-
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
19-
"hex"
20-
),
15+
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
2116
2,
2217
8
2318
);
@@ -31,16 +26,10 @@ describe("vote cast certificate tests", function () {
3126

3227
let settings = new wallet.Settings(settings_json);
3328
let proposal = new wallet.Proposal(
34-
Buffer.from(
35-
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
36-
"hex"
37-
),
29+
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
3830
4,
3931
8,
40-
Buffer.from(
41-
"bed88887abe0a84f64691fe0bdfa3daf1a6cd697a13f07ae07588910ce39c927",
42-
"hex"
43-
)
32+
"bed88887abe0a84f64691fe0bdfa3daf1a6cd697a13f07ae07588910ce39c927"
4433
);
4534
let vote = new wallet.Vote(proposal, 0, new wallet.BlockDate(0, 1), 1, 1);
4635
let fragments = wallet.signVotes([vote], settings, private_key);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ function signVotes(votes, settings, privateKey) {
5656
vote.proposal.voteEncKey != undefined
5757
) {
5858
let payload = wasm.Payload.new_private(
59-
wasm.VotePlanId.from_bytes(vote.proposal.votePlan),
59+
wasm.VotePlanId.from_hex(vote.proposal.votePlan),
6060
vote.proposal.options,
6161
vote.choice,
6262
vote.proposal.voteEncKey
6363
);
6464
voteCast = wasm.VoteCast.new(
65-
wasm.VotePlanId.from_bytes(vote.proposal.votePlan),
65+
wasm.VotePlanId.from_hex(vote.proposal.votePlan),
6666
vote.proposal.proposalIndex,
6767
payload
6868
);
6969
} else {
7070
let payload = wasm.Payload.new_public(vote.choice);
7171
voteCast = wasm.VoteCast.new(
72-
wasm.VotePlanId.from_bytes(vote.proposal.votePlan),
72+
wasm.VotePlanId.from_hex(vote.proposal.votePlan),
7373
vote.proposal.proposalIndex,
7474
payload
7575
);

src/chain-wallet-libs/bindings/wallet-wasm-js/src/certificates/vote_plan.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ pub struct VotePlanId(pub(crate) VotePlanIdLib);
1111

1212
#[wasm_bindgen]
1313
impl VotePlanId {
14+
pub fn from_hex(hex_data: String) -> Result<VotePlanId, JsValue> {
15+
Ok(VotePlanId(
16+
VotePlanIdLib::try_from(
17+
hex::decode(hex_data)
18+
.map_err(|e| JsValue::from(e.to_string()))?
19+
.as_slice(),
20+
)
21+
.map_err(|e| JsValue::from(e.to_string()))?,
22+
))
23+
}
1424
pub fn from_bytes(bytes: &[u8]) -> Result<VotePlanId, JsValue> {
1525
Ok(VotePlanId(
1626
VotePlanIdLib::try_from(bytes).map_err(|e| JsValue::from(e.to_string()))?,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ impl VoteCastTxBuilder {
6363
/// of the account.
6464
pub fn build_tx(
6565
mut self,
66-
account: &[u8],
66+
hex_account: String,
6767
counter: u32,
6868
lane: usize,
6969
) -> Result<VoteCastTxBuilder, JsValue> {
7070
self.0 = self
7171
.0
7272
.build_tx(
73-
account,
73+
hex::decode(hex_account)
74+
.map_err(|e| JsValue::from(e.to_string()))?
75+
.as_slice(),
7476
SpendingCounter::new(lane, counter).map_err(|e| JsValue::from(e.to_string()))?,
7577
)
7678
.map_err(|e| JsValue::from(e.to_string()))?;

0 commit comments

Comments
 (0)