@@ -163,18 +163,23 @@ pub fn log_initial_transfer(
163163
164164#[ hdk_extern]
165165pub fn get_validation_history ( item_hash : ActionHash ) -> ExternResult < Vec < ValidationReceipt > > {
166- let links = get_links ( GetLinksInput :: new (
167- item_hash. into ( ) ,
168- LinkTypes :: ValidatedItemToReceipt ,
169- None ,
170- ) ) ?;
166+ let links = get_links (
167+ GetLinksInputBuilder :: try_new ( item_hash, LinkTypes :: ValidatedItemToReceipt ) ?. build ( ) ,
168+ ) ?;
171169 let mut receipts = Vec :: new ( ) ;
172170
173171 for link in links {
174- if let Some ( record) = get ( link. target . into ( ) , GetOptions :: default ( ) ) ? {
175- if let Ok ( Some ( EntryTypes :: ValidationReceipt ( receipt) ) ) = record. entry ( ) . to_app_option ( )
176- {
177- receipts. push ( receipt) ;
172+ if let Ok ( any_dht_hash) = AnyDhtHash :: try_from ( link. target . clone ( ) ) {
173+ if let Some ( record) = get ( any_dht_hash, GetOptions :: default ( ) ) ? {
174+ if let Ok ( Some ( EntryTypes :: ValidationReceipt ( receipt) ) ) =
175+ record. entry ( ) . to_app_option :: < EntryTypes > ( ) . map_err ( |_| {
176+ wasm_error ! ( WasmErrorInner :: Guest (
177+ "Failed to deserialize validation receipt" . into( )
178+ ) )
179+ } )
180+ {
181+ receipts. push ( receipt) ;
182+ }
178183 }
179184 }
180185 }
@@ -241,19 +246,23 @@ pub fn create_resource_validation(
241246pub fn check_validation_status (
242247 resource_hash : ActionHash ,
243248) -> ExternResult < Option < ResourceValidation > > {
244- let links = get_links ( GetLinksInput :: new (
245- resource_hash. into ( ) ,
246- LinkTypes :: ResourceToValidation ,
247- None ,
248- ) ) ?;
249+ let links = get_links (
250+ GetLinksInputBuilder :: try_new ( resource_hash, LinkTypes :: ResourceToValidation ) ?. build ( ) ,
251+ ) ?;
249252
250253 // Get the most recent validation (there should only be one per resource)
251254 if let Some ( link) = links. first ( ) {
252- if let Some ( record) = get ( link. target . clone ( ) . into ( ) , GetOptions :: default ( ) ) ? {
253- if let Ok ( Some ( EntryTypes :: ResourceValidation ( validation) ) ) =
254- record. entry ( ) . to_app_option ( )
255- {
256- return Ok ( Some ( validation) ) ;
255+ if let Ok ( any_dht_hash) = AnyDhtHash :: try_from ( link. target . clone ( ) ) {
256+ if let Some ( record) = get ( any_dht_hash, GetOptions :: default ( ) ) ? {
257+ if let Ok ( Some ( EntryTypes :: ResourceValidation ( validation) ) ) =
258+ record. entry ( ) . to_app_option :: < EntryTypes > ( ) . map_err ( |_| {
259+ wasm_error ! ( WasmErrorInner :: Guest (
260+ "Failed to deserialize resource validation" . into( )
261+ ) )
262+ } )
263+ {
264+ return Ok ( Some ( validation) ) ;
265+ }
257266 }
258267 }
259268 }
@@ -319,18 +328,23 @@ pub fn get_all_validation_receipts(_: ()) -> ExternResult<Vec<ValidationReceipt>
319328 let path = Path :: from ( "all_validation_receipts" ) ;
320329 let anchor_hash = path. path_entry_hash ( ) ?;
321330
322- let links = get_links ( GetLinksInput :: new (
323- anchor_hash. into ( ) ,
324- LinkTypes :: AllValidationReceipts ,
325- None ,
326- ) ) ?;
331+ let links = get_links (
332+ GetLinksInputBuilder :: try_new ( anchor_hash, LinkTypes :: AllValidationReceipts ) ?. build ( ) ,
333+ ) ?;
327334 let mut receipts = Vec :: new ( ) ;
328335
329336 for link in links {
330- if let Some ( record) = get ( link. target . into ( ) , GetOptions :: default ( ) ) ? {
331- if let Ok ( Some ( EntryTypes :: ValidationReceipt ( receipt) ) ) = record. entry ( ) . to_app_option ( )
332- {
333- receipts. push ( receipt) ;
337+ if let Ok ( any_dht_hash) = AnyDhtHash :: try_from ( link. target . clone ( ) ) {
338+ if let Some ( record) = get ( any_dht_hash, GetOptions :: default ( ) ) ? {
339+ if let Ok ( Some ( EntryTypes :: ValidationReceipt ( receipt) ) ) =
340+ record. entry ( ) . to_app_option :: < EntryTypes > ( ) . map_err ( |_| {
341+ wasm_error ! ( WasmErrorInner :: Guest (
342+ "Failed to deserialize validation receipt" . into( )
343+ ) )
344+ } )
345+ {
346+ receipts. push ( receipt) ;
347+ }
334348 }
335349 }
336350 }
@@ -343,17 +357,23 @@ pub fn get_all_economic_events(_: ()) -> ExternResult<Vec<EconomicEvent>> {
343357 let path = Path :: from ( "all_economic_events" ) ;
344358 let anchor_hash = path. path_entry_hash ( ) ?;
345359
346- let links = get_links ( GetLinksInput :: new (
347- anchor_hash. into ( ) ,
348- LinkTypes :: AllEconomicEvents ,
349- None ,
350- ) ) ?;
360+ let links = get_links (
361+ GetLinksInputBuilder :: try_new ( anchor_hash, LinkTypes :: AllEconomicEvents ) ?. build ( ) ,
362+ ) ?;
351363 let mut events = Vec :: new ( ) ;
352364
353365 for link in links {
354- if let Some ( record) = get ( link. target . into ( ) , GetOptions :: default ( ) ) ? {
355- if let Ok ( Some ( EntryTypes :: EconomicEvent ( event) ) ) = record. entry ( ) . to_app_option ( ) {
356- events. push ( event) ;
366+ if let Ok ( any_dht_hash) = AnyDhtHash :: try_from ( link. target . clone ( ) ) {
367+ if let Some ( record) = get ( any_dht_hash, GetOptions :: default ( ) ) ? {
368+ if let Ok ( Some ( EntryTypes :: EconomicEvent ( event) ) ) =
369+ record. entry ( ) . to_app_option :: < EntryTypes > ( ) . map_err ( |_| {
370+ wasm_error ! ( WasmErrorInner :: Guest (
371+ "Failed to deserialize economic event" . into( )
372+ ) )
373+ } )
374+ {
375+ events. push ( event) ;
376+ }
357377 }
358378 }
359379 }
0 commit comments