17
17
18
18
use crate :: mutation_utils:: MutationUtil ;
19
19
use db3_crypto:: db3_address:: DB3Address ;
20
- use db3_crypto:: id:: DbId ;
20
+ use db3_crypto:: id:: { DbId , TxId } ;
21
21
use db3_error:: Result ;
22
+ use db3_proto:: db3_mutation_v2_proto:: { MutationAction , MutationRollupStatus } ;
22
23
use db3_proto:: db3_storage_proto:: {
23
- storage_node_server:: StorageNode , ExtraItem , GetNonceRequest , GetNonceResponse ,
24
- SendMutationRequest , SendMutationResponse ,
24
+ storage_node_server:: StorageNode , ExtraItem , GetMutationBodyRequest , GetMutationBodyResponse ,
25
+ GetMutationHeaderRequest , GetMutationHeaderResponse , GetNonceRequest , GetNonceResponse ,
26
+ ScanMutationHeaderRequest , ScanMutationHeaderResponse , SendMutationRequest ,
27
+ SendMutationResponse ,
25
28
} ;
26
-
27
- use db3_proto:: db3_mutation_v2_proto:: MutationAction ;
28
29
use db3_storage:: mutation_store:: { MutationStore , MutationStoreConfig } ;
29
30
use db3_storage:: state_store:: { StateStore , StateStoreConfig } ;
30
31
use tonic:: { Request , Response , Status } ;
@@ -56,6 +57,47 @@ impl StorageNodeV2Impl {
56
57
57
58
#[ tonic:: async_trait]
58
59
impl StorageNode for StorageNodeV2Impl {
60
+ async fn get_mutation_body (
61
+ & self ,
62
+ request : Request < GetMutationBodyRequest > ,
63
+ ) -> std:: result:: Result < Response < GetMutationBodyResponse > , Status > {
64
+ let r = request. into_inner ( ) ;
65
+ let tx_id =
66
+ TxId :: try_from_hex ( r. id . as_str ( ) ) . map_err ( |e| Status :: internal ( format ! ( "{e}" ) ) ) ?;
67
+ let body = self
68
+ . storage
69
+ . get_mutation ( & tx_id)
70
+ . map_err ( |e| Status :: internal ( format ! ( "{e}" ) ) ) ?;
71
+ Ok ( Response :: new ( GetMutationBodyResponse { body } ) )
72
+ }
73
+
74
+ async fn scan_mutation_header (
75
+ & self ,
76
+ request : Request < ScanMutationHeaderRequest > ,
77
+ ) -> std:: result:: Result < Response < ScanMutationHeaderResponse > , Status > {
78
+ let r = request. into_inner ( ) ;
79
+ let headers = self
80
+ . storage
81
+ . scan_mutation_headers ( r. start , r. limit )
82
+ . map_err ( |e| Status :: internal ( format ! ( "{e}" ) ) ) ?;
83
+ Ok ( Response :: new ( ScanMutationHeaderResponse { headers } ) )
84
+ }
85
+
86
+ async fn get_mutation_header (
87
+ & self ,
88
+ request : Request < GetMutationHeaderRequest > ,
89
+ ) -> std:: result:: Result < Response < GetMutationHeaderResponse > , Status > {
90
+ let r = request. into_inner ( ) ;
91
+ let header = self
92
+ . storage
93
+ . get_mutation_header ( r. block_id , r. order_id )
94
+ . map_err ( |e| Status :: internal ( format ! ( "{e}" ) ) ) ?;
95
+ Ok ( Response :: new ( GetMutationHeaderResponse {
96
+ header,
97
+ status : MutationRollupStatus :: Pending . into ( ) ,
98
+ rollup_tx : vec ! [ ] ,
99
+ } ) )
100
+ }
59
101
async fn get_nonce (
60
102
& self ,
61
103
request : Request < GetNonceRequest > ,
@@ -88,9 +130,9 @@ impl StorageNode for StorageNodeV2Impl {
88
130
match self . state_store . incr_nonce ( & address, nonce) {
89
131
Ok ( _) => {
90
132
// mutation id
91
- let id = self
133
+ let ( id , block , order ) = self
92
134
. storage
93
- . add_mutation ( & r. payload , r. signature . as_bytes ( ) , & address)
135
+ . add_mutation ( & r. payload , r. signature . as_str ( ) , & address)
94
136
. map_err ( |e| Status :: internal ( format ! ( "{e}" ) ) ) ?;
95
137
match action {
96
138
MutationAction :: CreateDocumentDb => {
@@ -100,18 +142,23 @@ impl StorageNode for StorageNodeV2Impl {
100
142
key : "db_addr" . to_string ( ) ,
101
143
value : db_addr,
102
144
} ;
145
+
103
146
Ok ( Response :: new ( SendMutationResponse {
104
147
id,
105
148
code : 0 ,
106
149
msg : "ok" . to_string ( ) ,
107
150
items : vec ! [ item] ,
151
+ block,
152
+ order,
108
153
} ) )
109
154
}
110
155
_ => Ok ( Response :: new ( SendMutationResponse {
111
156
id,
112
157
code : 0 ,
113
158
msg : "ok" . to_string ( ) ,
114
159
items : vec ! [ ] ,
160
+ block,
161
+ order,
115
162
} ) ) ,
116
163
}
117
164
}
@@ -120,6 +167,8 @@ impl StorageNode for StorageNodeV2Impl {
120
167
code : 1 ,
121
168
msg : "bad nonce" . to_string ( ) ,
122
169
items : vec ! [ ] ,
170
+ block : 0 ,
171
+ order : 0 ,
123
172
} ) ) ,
124
173
}
125
174
}
0 commit comments