@@ -4,6 +4,7 @@ use crate::jcli_lib::{
4
4
} ;
5
5
use bech32:: { self , ToBase32 as _} ;
6
6
use chain_core:: property:: Serialize as _;
7
+ use chain_impl_mockchain:: key:: EitherEd25519SecretKey ;
7
8
use chain_impl_mockchain:: {
8
9
account:: SpendingCounter ,
9
10
header:: HeaderId ,
@@ -62,38 +63,14 @@ impl std::str::FromStr for WitnessType {
62
63
63
64
impl MkWitness {
64
65
pub fn exec ( self ) -> Result < ( ) , Error > {
65
- let witness = match self . witness_type {
66
- WitnessType :: UTxO => {
67
- let secret_key = read_ed25519_secret_key_from_file ( & self . secret ) ?;
68
- Witness :: new_utxo ( & self . genesis_block_hash , & self . sign_data_hash , |d| {
69
- secret_key. sign ( d)
70
- } )
71
- }
72
- WitnessType :: OldUTxO => {
73
- let secret_key = read_ed25519_secret_key_from_file ( & self . secret ) ?;
74
- Witness :: new_old_utxo (
75
- & self . genesis_block_hash ,
76
- & self . sign_data_hash ,
77
- |d| ( secret_key. to_public ( ) , secret_key. sign ( d) ) ,
78
- & [ 0 ; 32 ] ,
79
- )
80
- }
81
- WitnessType :: Account => {
82
- let account_spending_counter = self
83
- . account_spending_counter
84
- . ok_or ( Error :: MakeWitnessAccountCounterMissing )
85
- . map ( SpendingCounter :: from) ?;
86
-
87
- let secret_key = read_ed25519_secret_key_from_file ( & self . secret ) ?;
88
- Witness :: new_account (
89
- & self . genesis_block_hash ,
90
- & self . sign_data_hash ,
91
- account_spending_counter,
92
- |d| secret_key. sign ( d) ,
93
- )
94
- }
95
- } ;
96
-
66
+ let secret_key = read_ed25519_secret_key_from_file ( & self . secret ) ?;
67
+ let witness = make_witness (
68
+ & self . witness_type ,
69
+ & self . genesis_block_hash ,
70
+ & self . sign_data_hash ,
71
+ self . account_spending_counter . map ( SpendingCounter :: from) ,
72
+ & secret_key,
73
+ ) ?;
97
74
self . write_witness ( & witness)
98
75
}
99
76
@@ -115,3 +92,30 @@ impl MkWitness {
115
92
} )
116
93
}
117
94
}
95
+
96
+ pub fn make_witness (
97
+ witness_type : & WitnessType ,
98
+ genesis_block_hash : & HeaderId ,
99
+ sign_data_hash : & TransactionSignDataHash ,
100
+ account_spending_counter : Option < SpendingCounter > ,
101
+ secret_key : & EitherEd25519SecretKey ,
102
+ ) -> Result < Witness , Error > {
103
+ let witness = match witness_type {
104
+ WitnessType :: UTxO => {
105
+ Witness :: new_utxo ( genesis_block_hash, sign_data_hash, |d| secret_key. sign ( d) )
106
+ }
107
+ WitnessType :: OldUTxO => Witness :: new_old_utxo (
108
+ genesis_block_hash,
109
+ sign_data_hash,
110
+ |d| ( secret_key. to_public ( ) , secret_key. sign ( d) ) ,
111
+ & [ 0 ; 32 ] ,
112
+ ) ,
113
+ WitnessType :: Account => Witness :: new_account (
114
+ genesis_block_hash,
115
+ sign_data_hash,
116
+ account_spending_counter. ok_or ( Error :: MakeWitnessAccountCounterMissing ) ?,
117
+ |d| secret_key. sign ( d) ,
118
+ ) ,
119
+ } ;
120
+ Ok ( witness)
121
+ }
0 commit comments