Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r2r] Add NAV cold_staking script type #1466

Merged
merged 2 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions mm2src/mm2_bitcoin/rpc/src/v1/types/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum ScriptType {
Call,
Create,
LelantusMint,
ColdStaking,
}

impl From<GlobalScriptType> for ScriptType {
Expand All @@ -36,6 +37,7 @@ impl From<GlobalScriptType> for ScriptType {
GlobalScriptType::CreateSender => ScriptType::CreateSender,
GlobalScriptType::Call => ScriptType::Call,
GlobalScriptType::Create => ScriptType::Create,
GlobalScriptType::ColdStaking => ScriptType::ColdStaking,
}
}
}
Expand All @@ -59,6 +61,7 @@ impl Serialize for ScriptType {
ScriptType::Call => "call".serialize(serializer),
ScriptType::Create => "create".serialize(serializer),
ScriptType::LelantusMint => "lelantusmint".serialize(serializer),
ScriptType::ColdStaking => "cold_staking".serialize(serializer),
}
}
}
Expand Down Expand Up @@ -95,6 +98,7 @@ impl<'a> Deserialize<'a> for ScriptType {
"call" => Ok(ScriptType::Call),
"create" => Ok(ScriptType::Create),
"lelantusmint" => Ok(ScriptType::LelantusMint),
"cold_staking" => Ok(ScriptType::ColdStaking),
_ => Err(E::invalid_value(Unexpected::Str(value), &self)),
}
}
Expand Down Expand Up @@ -144,6 +148,10 @@ mod tests {
);
assert_eq!(serde_json::to_string(&ScriptType::Call).unwrap(), r#""call""#);
assert_eq!(serde_json::to_string(&ScriptType::Create).unwrap(), r#""create""#);
assert_eq!(
serde_json::to_string(&ScriptType::ColdStaking).unwrap(),
r#""cold_staking""#
);
}

#[test]
Expand Down Expand Up @@ -196,5 +204,9 @@ mod tests {
serde_json::from_str::<ScriptType>(r#""create""#).unwrap(),
ScriptType::Create
);
assert_eq!(
serde_json::from_str::<ScriptType>(r#""cold_staking""#).unwrap(),
ScriptType::ColdStaking
);
}
}
40 changes: 40 additions & 0 deletions mm2src/mm2_bitcoin/rpc/src/v1/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2039,4 +2039,44 @@ mod tests {

let _tx: Transaction = serde_json::from_str(json_str).unwrap();
}

#[test]
fn test_nav_cold_staking_script_pubkey() {
let json_str = r#"[
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
{
"value": 10,
"valuesat": 1000000000,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 e6761d199b7a3137c98056e49b7339b9a7ab3f5e OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914e6761d199b7a3137c98056e49b7339b9a7ab3f5e88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"NgvY6ZMtLoo2Zseh9MBgTTHN2Uvt6R5XsB"
]
},
"spentTxId": "4cc8e8ff9b4128f8c013c6bea74d756b44f5f2c7faf9a6303acf9ffc1c4cdb46",
"spentHeight": 6506904
},
{
"value": 11403.679,
"valuesat": 1140367900000,
"n": 1,
"scriptPubKey": {
"asm": "OP_COINSTAKE OP_IF OP_DUP OP_HASH160 d5169fad89fc585816fb53615440b4cec510e460 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 2523d5cf81a07f0a7591af6733ea582da3643069 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF",
"hex": "c66376a914d5169fad89fc585816fb53615440b4cec510e46088ac6776a9142523d5cf81a07f0a7591af6733ea582da364306988ac68",
"reqSigs": 1,
"type": "cold_staking",
"addresses": [
"NfLgDYL4C3KKXDS8tLRAFM7spvLykV8v9A",
"NPJM7j7P9VhChdXCKRWFto1feWPYcAPQqW"
]
}
}
]"#;

let vout: Vec<SignedTransactionOutput> = serde_json::from_str(json_str).unwrap();
assert_eq!(vout[1].script.script_type, ScriptType::ColdStaking);
}
}
4 changes: 4 additions & 0 deletions mm2src/mm2_bitcoin/script/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum ScriptType {
CreateSender,
Call,
Create,
ColdStaking,
}

/// Address from Script
Expand Down Expand Up @@ -461,6 +462,9 @@ impl Script {
ScriptType::Create => {
Ok(vec![]) // TODO
},
ScriptType::ColdStaking => {
Ok(vec![]) // TODO
},
}
}

Expand Down