@@ -961,6 +961,17 @@ impl BitGoPsbt {
961961 }
962962 }
963963
964+ /// Get the Zcash consensus branch ID from the PSBT proprietary map (returns None for non-Zcash PSBTs)
965+ pub fn consensus_branch_id ( & self ) -> Option < u32 > {
966+ use crate :: fixed_script_wallet:: bitgo_psbt:: {
967+ propkv:: get_zec_consensus_branch_id, BitGoPsbt as InnerBitGoPsbt ,
968+ } ;
969+ match & self . psbt {
970+ InnerBitGoPsbt :: Zcash ( z, _) => get_zec_consensus_branch_id ( & z. psbt ) ,
971+ _ => None ,
972+ }
973+ }
974+
964975 pub fn get_outputs_with_address ( & self ) -> Result < JsValue , WasmUtxoError > {
965976 crate :: wasm:: psbt:: get_outputs_with_address_from_psbt ( self . psbt . psbt ( ) , self . psbt . network ( ) )
966977 }
@@ -1943,3 +1954,23 @@ impl BitGoPsbt {
19431954}
19441955
19451956impl_wasm_psbt_ops ! ( BitGoPsbt , psbt) ;
1957+
1958+ /// Return the Zcash consensus branch ID active at `height` on `network`.
1959+ ///
1960+ /// `network`: "zcash" / "zec" for mainnet, "zcashTest" / "tzec" for testnet.
1961+ /// Returns `None` if `height` is before Overwinter activation.
1962+ /// Throws if `network` is not a recognised Zcash network name.
1963+ #[ wasm_bindgen]
1964+ pub fn zcash_branch_id_for_height ( network : & str , height : u32 ) -> Result < Option < u32 > , JsValue > {
1965+ let is_mainnet = match network {
1966+ "zcash" | "zec" => true ,
1967+ "zcashTest" | "tzec" => false ,
1968+ _ => {
1969+ return Err ( JsValue :: from_str ( & format ! (
1970+ "unknown Zcash network {:?}: expected \" zcash\" , \" zec\" , \" zcashTest\" , or \" tzec\" " ,
1971+ network
1972+ ) ) )
1973+ }
1974+ } ;
1975+ Ok ( crate :: zcash:: branch_id_for_height ( height, is_mainnet) )
1976+ }
0 commit comments