Skip to content

Commit 3c0f4b5

Browse files
authored
fix KDA field for klv transactions (#113)
1 parent d92f582 commit 3c0f4b5

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

packages/kos-mobile/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ mod tests {
506506
"The sender doesn't match"
507507
);
508508
assert_eq!(
509-
transaction.raw, "7b22426c6f636b223a6e756c6c2c2252617744617461223a7b2242616e647769647468466565223a313030303030302c22436861696e4944223a224d5441774e444977222c22436f6e7472616374223a5b7b22506172616d65746572223a7b22747970655f75726c223a22747970652e676f6f676c65617069732e636f6d2f70726f746f2e5472616e73666572436f6e7472616374222c2276616c7565223a224369417973796730416a38786a2f72723558475536694a2b41544932396d6e52485330573042724331767a304342674b227d2c2254797065223a6e756c6c7d5d2c2244617461223a6e756c6c2c224b417070466565223a3530303030302c224b6461466565223a6e756c6c2c224e6f6e6365223a33392c225065726d697373696f6e4944223a6e756c6c2c2253656e646572223a22354273794f6c6366325658676e4e5157595039455a6350305270504966792b75704b44385149636e794f6f3d222c2256657273696f6e223a317d2c225265636569707473223a6e756c6c2c22526573756c74223a6e756c6c2c22526573756c74436f6465223a6e756c6c2c225369676e6174757265223a5b2267555a444950537853713430516a54424d33382f4441417557546d37443154486f324b5756716869545943756d354f2b4f53577754596c6749553052674a36756e6767316375434a50636d59574e676a444b412f44413d3d225d7d",
509+
transaction.raw, "7b22426c6f636b223a6e756c6c2c2252617744617461223a7b2242616e647769647468466565223a313030303030302c22436861696e4944223a224d5441774e444977222c22436f6e7472616374223a5b7b22506172616d65746572223a7b22747970655f75726c223a22747970652e676f6f676c65617069732e636f6d2f70726f746f2e5472616e73666572436f6e7472616374222c2276616c7565223a224369417973796730416a38786a2f72723558475536694a2b41544932396d6e52485330573042724331767a304342674b227d2c2254797065223a6e756c6c7d5d2c2244617461223a6e756c6c2c224b417070466565223a3530303030302c224b4441466565223a6e756c6c2c224e6f6e6365223a33392c225065726d697373696f6e4944223a6e756c6c2c2253656e646572223a22354273794f6c6366325658676e4e5157595039455a6350305270504966792b75704b44385149636e794f6f3d222c2256657273696f6e223a317d2c225265636569707473223a6e756c6c2c22526573756c74223a6e756c6c2c22526573756c74436f6465223a6e756c6c2c225369676e6174757265223a5b2267555a444950537853713430516a54424d33382f4441417557546d37443154486f324b5756716869545943756d354f2b4f53577754596c6749553052674a36756e6767316375434a50636d59574e676a444b412f44413d3d225d7d",
510510
"The raw doesn't match"
511511
);
512512
assert_eq!(

packages/kos/src/chains/klv/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,56 @@ mod test {
339339
.unwrap()
340340
);
341341
}
342+
#[test]
343+
fn test_sign_tx_5() {
344+
let pvk = hex::decode("1ab42cc412b618bdea3a599e3c9bae199ebf030895b039e9db1e30dafb12b727")
345+
.unwrap();
346+
347+
let json = r#"
348+
{
349+
"RawData": {
350+
"Nonce": 606,
351+
"Sender": "SqQFUzLDtZNzXexeY++BMVH5GTKLDMSxo72GoRqjZz0=",
352+
"Contract": [
353+
{
354+
"Parameter": {
355+
"type_url": "type.googleapis.com/proto.TransferContract",
356+
"value": "CiBI/KqGTZBj8/J8YhvX20xb9NP6l5eXRCBmJsWERlhmSRIDS0xWGMCEPQ=="
357+
}
358+
}
359+
],
360+
"Data": [
361+
""
362+
],
363+
"KAppFee": 1000000,
364+
"BandwidthFee": 2000000,
365+
"Version": 1,
366+
"ChainID": "MTA4",
367+
"KDAFee": {
368+
"KDA": "Q0hJUFMtMUdaUA==",
369+
"Amount": 688200
370+
}
371+
}
372+
}"#;
373+
let raw_tx = json.as_bytes().to_vec();
374+
375+
let tx = crate::chains::Transaction {
376+
raw_data: raw_tx,
377+
tx_hash: Vec::new(),
378+
signature: Vec::new(),
379+
options: None,
380+
};
381+
382+
let result_tx = crate::chains::klv::KLV {}.sign_tx(pvk, tx).unwrap();
383+
384+
assert_eq!(
385+
result_tx.tx_hash,
386+
vec![
387+
60, 222, 134, 3, 87, 86, 2, 184, 223, 221, 53, 134, 54, 27, 20, 178, 197, 31, 20,
388+
66, 12, 107, 186, 61, 21, 82, 78, 66, 210, 190, 124, 194
389+
]
390+
);
391+
}
342392

343393
#[test]
344394
fn test_decode_klv_tx() {

packages/kos/src/chains/klv/models.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct Raw {
5050
pub version: Option<u32>,
5151
#[Rename = "ChainID"]
5252
pub chain_id: String,
53-
#[Rename = "KdaFee"] // Use this to match the exact JSON field name for this field
53+
#[Rename = "KDAFee"] // Use this to match the exact JSON field name for this field
5454
pub kda_fee: ::core::option::Option<KdaFee>,
5555
}
5656

@@ -72,7 +72,7 @@ pub struct Parameter {
7272

7373
#[derive(Clone, PartialEq, Serialize, Deserialize)]
7474
pub struct KdaFee {
75-
#[Rename = "Kda"]
75+
#[Rename = "KDA"]
7676
pub kda: String,
7777
#[Rename = "Amount"]
7878
pub amount: i64,

0 commit comments

Comments
 (0)