/
export_helpers.go
80 lines (65 loc) · 2.09 KB
/
export_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package docs
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// exportDocuments exports all the Documents in the store to a slice.
func exportDocuments(ctx sdk.Context, keeper Keeper) []Document {
documents := []Document{}
di := keeper.DocumentsIterator(ctx)
defer di.Close()
for ; di.Valid(); di.Next() {
document, duuid, err := keeper.ExtractDocument(ctx, di.Key())
if err != nil {
panic(
fmt.Sprintf(
"could not find document with UUID %s even though the user has an associated received document",
duuid,
),
)
}
documents = append(documents, document)
}
return documents
}
// exportReceipts exports all the Receipts in the store to a slice.
func exportReceipts(ctx sdk.Context, keeper Keeper) []DocumentReceipt {
receipts := []DocumentReceipt{}
sentDri, _ := keeper.ReceiptsIterators(ctx)
defer sentDri.Close()
// just iterate through sent receipt, received receipts are the same:
// the per-user selection logic happens on the key-level
for ; sentDri.Valid(); sentDri.Next() {
receipt, uuid, err := keeper.ExtractReceipt(ctx, sentDri.Value())
if err != nil {
panic(
fmt.Sprintf(
"could not find document receipt with UUID %s even though the user has an associated document with it",
uuid,
),
)
}
receipts = append(receipts, receipt)
}
return receipts
}
// exportMetadataSchema exports all the MetadataSchema in the store to a slice.
func exportMetadataSchemes(ctx sdk.Context, keeper Keeper) []MetadataSchema {
sms := []MetadataSchema{}
smsi := keeper.SupportedMetadataSchemesIterator(ctx)
defer smsi.Close()
for ; smsi.Valid(); smsi.Next() {
sms = append(sms, keeper.ExtractMetadataSchema(smsi.Value()))
}
return sms
}
// exportTrustedSchemaProviders exports all the TrustedSchemaProviders in the store to a slice.
func exportTrustedSchemaProviders(ctx sdk.Context, keeper Keeper) []sdk.AccAddress {
tsps := []sdk.AccAddress{}
tspi := keeper.TrustedSchemaProposersIterator(ctx)
defer tspi.Close()
for ; tspi.Valid(); tspi.Next() {
tsps = append(tsps, keeper.ExtractTrustedSchemaProposer(tspi.Value()))
}
return tsps
}