@@ -10,16 +10,15 @@ use crate::public_key::ProtobufPublicKey;
10
10
use crate :: transaction:: {
11
11
Coin , Fee , SignMode , SignedTransaction , SignerInfo , TxBody , UnsignedTransaction ,
12
12
} ;
13
- use std:: borrow:: Cow ;
14
13
use std:: marker:: PhantomData ;
15
14
use tw_coin_entry:: error:: prelude:: * ;
16
15
use tw_memory:: Data ;
17
16
use tw_proto:: serialize;
18
17
19
- pub fn build_coin ( coin : & Coin ) -> base_proto:: Coin < ' static > {
18
+ pub fn build_coin ( coin : & Coin ) -> base_proto:: Coin {
20
19
base_proto:: Coin {
21
- amount : coin. amount . to_string ( ) . into ( ) ,
22
- denom : coin. denom . clone ( ) . into ( ) ,
20
+ amount : coin. amount . to_string ( ) ,
21
+ denom : coin. denom . clone ( ) ,
23
22
}
24
23
}
25
24
@@ -38,73 +37,62 @@ pub struct SignDirectArgs {
38
37
impl < Context : CosmosContext > ProtobufSerializer < Context > {
39
38
/// Serializes a signed transaction into the Cosmos [`tx_proto::TxRaw`] message.
40
39
/// [`tx_proto::TxRaw`] can be broadcasted to the network.
41
- pub fn build_signed_tx (
42
- signed : & SignedTransaction < Context > ,
43
- ) -> SigningResult < tx_proto:: TxRaw < ' static > > {
40
+ pub fn build_signed_tx ( signed : & SignedTransaction < Context > ) -> SigningResult < tx_proto:: TxRaw > {
44
41
let tx_body = Self :: build_tx_body ( & signed. tx_body ) ?;
45
- let body_bytes = serialize ( & tx_body)
46
- . expect ( "Unexpected error on tx_body serialization" )
47
- . into ( ) ;
42
+ let body_bytes = serialize ( & tx_body) . expect ( "Unexpected error on tx_body serialization" ) ;
48
43
49
44
let auth_info = Self :: build_auth_info ( & signed. signer , & signed. fee ) ;
50
- let auth_info_bytes = serialize ( & auth_info)
51
- . expect ( "Unexpected error on auth_info serialization" )
52
- . into ( ) ;
45
+ let auth_info_bytes =
46
+ serialize ( & auth_info) . expect ( "Unexpected error on auth_info serialization" ) ;
53
47
54
48
Ok ( tx_proto:: TxRaw {
55
49
body_bytes,
56
50
auth_info_bytes,
57
- signatures : vec ! [ signed. signature. clone( ) . into ( ) ] ,
51
+ signatures : vec ! [ signed. signature. clone( ) ] ,
58
52
} )
59
53
}
60
54
61
- pub fn build_direct_signed_tx (
62
- args : & SignDirectArgs ,
63
- signature : Data ,
64
- ) -> tx_proto:: TxRaw < ' static > {
55
+ pub fn build_direct_signed_tx ( args : & SignDirectArgs , signature : Data ) -> tx_proto:: TxRaw {
65
56
tx_proto:: TxRaw {
66
- body_bytes : args. tx_body . clone ( ) . into ( ) ,
67
- auth_info_bytes : args. auth_info . clone ( ) . into ( ) ,
68
- signatures : vec ! [ signature. into ( ) ] ,
57
+ body_bytes : args. tx_body . clone ( ) ,
58
+ auth_info_bytes : args. auth_info . clone ( ) ,
59
+ signatures : vec ! [ signature] ,
69
60
}
70
61
}
71
62
72
63
/// Serializes an unsigned transaction into the Cosmos [`tx_proto::SignDoc`] message.
73
64
/// [`tx_proto::SignDoc`] is used to generate a transaction prehash and sign it.
74
65
pub fn build_sign_doc (
75
66
unsigned : & UnsignedTransaction < Context > ,
76
- ) -> SigningResult < tx_proto:: SignDoc < ' static > > {
67
+ ) -> SigningResult < tx_proto:: SignDoc > {
77
68
let tx_body = Self :: build_tx_body ( & unsigned. tx_body ) ?;
78
- let body_bytes = serialize ( & tx_body)
79
- . expect ( "Unexpected error on tx_body serialization" )
80
- . into ( ) ;
69
+ let body_bytes = serialize ( & tx_body) . expect ( "Unexpected error on tx_body serialization" ) ;
81
70
82
71
let auth_info = Self :: build_auth_info ( & unsigned. signer , & unsigned. fee ) ;
83
- let auth_info_bytes = serialize ( & auth_info)
84
- . expect ( "Unexpected error on auth_info serialization" )
85
- . into ( ) ;
72
+ let auth_info_bytes =
73
+ serialize ( & auth_info) . expect ( "Unexpected error on auth_info serialization" ) ;
86
74
87
75
Ok ( tx_proto:: SignDoc {
88
76
body_bytes,
89
77
auth_info_bytes,
90
- chain_id : unsigned. chain_id . clone ( ) . into ( ) ,
78
+ chain_id : unsigned. chain_id . clone ( ) ,
91
79
account_number : unsigned. account_number ,
92
80
} )
93
81
}
94
82
95
- pub fn build_direct_sign_doc ( args : & SignDirectArgs ) -> tx_proto:: SignDoc < ' static > {
83
+ pub fn build_direct_sign_doc ( args : & SignDirectArgs ) -> tx_proto:: SignDoc {
96
84
tx_proto:: SignDoc {
97
- body_bytes : args. tx_body . clone ( ) . into ( ) ,
98
- auth_info_bytes : args. auth_info . clone ( ) . into ( ) ,
99
- chain_id : args. chain_id . clone ( ) . into ( ) ,
85
+ body_bytes : args. tx_body . clone ( ) ,
86
+ auth_info_bytes : args. auth_info . clone ( ) ,
87
+ chain_id : args. chain_id . clone ( ) ,
100
88
account_number : args. account_number ,
101
89
}
102
90
}
103
91
104
92
pub fn build_auth_info (
105
93
signer : & SignerInfo < Context :: PublicKey > ,
106
94
fee : & Fee < Context :: Address > ,
107
- ) -> tx_proto:: AuthInfo < ' static > {
95
+ ) -> tx_proto:: AuthInfo {
108
96
tx_proto:: AuthInfo {
109
97
signer_infos : vec ! [ Self :: build_signer_info( signer) ] ,
110
98
fee : Some ( Self :: build_fee ( fee) ) ,
@@ -113,7 +101,7 @@ impl<Context: CosmosContext> ProtobufSerializer<Context> {
113
101
}
114
102
}
115
103
116
- pub fn build_tx_body ( tx_body : & TxBody ) -> SigningResult < tx_proto:: TxBody < ' static > > {
104
+ pub fn build_tx_body ( tx_body : & TxBody ) -> SigningResult < tx_proto:: TxBody > {
117
105
let messages: Vec < _ > = tx_body
118
106
. messages
119
107
. iter ( )
@@ -122,14 +110,14 @@ impl<Context: CosmosContext> ProtobufSerializer<Context> {
122
110
123
111
Ok ( tx_proto:: TxBody {
124
112
messages,
125
- memo : tx_body. memo . clone ( ) . into ( ) ,
113
+ memo : tx_body. memo . clone ( ) ,
126
114
timeout_height : tx_body. timeout_height ,
127
115
extension_options : Vec :: default ( ) ,
128
116
non_critical_extension_options : Vec :: default ( ) ,
129
117
} )
130
118
}
131
119
132
- pub fn build_signer_info ( signer : & SignerInfo < Context :: PublicKey > ) -> tx_proto:: SignerInfo < ' static > {
120
+ pub fn build_signer_info ( signer : & SignerInfo < Context :: PublicKey > ) -> tx_proto:: SignerInfo {
133
121
use tx_proto:: mod_ModeInfo:: { self as mode_info, OneOfsum as SumEnum } ;
134
122
135
123
// Single is the mode info for a single signer. It is structured as a message
@@ -147,13 +135,13 @@ impl<Context: CosmosContext> ProtobufSerializer<Context> {
147
135
}
148
136
}
149
137
150
- fn build_fee ( fee : & Fee < Context :: Address > ) -> tx_proto:: Fee < ' static > {
138
+ fn build_fee ( fee : & Fee < Context :: Address > ) -> tx_proto:: Fee {
151
139
tx_proto:: Fee {
152
140
amount : fee. amounts . iter ( ) . map ( build_coin) . collect ( ) ,
153
141
gas_limit : fee. gas_limit ,
154
142
// Ignore `payer` and `granter` even if they set.
155
- payer : Cow :: default ( ) ,
156
- granter : Cow :: default ( ) ,
143
+ payer : String :: default ( ) ,
144
+ granter : String :: default ( ) ,
157
145
}
158
146
}
159
147
0 commit comments