forked from zerolabsgreen/zero-pl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed-dev.sh
executable file
·225 lines (204 loc) · 6.74 KB
/
seed-dev.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
X_API_KEY=$(grep SUPERADMIN_API_KEY .env | cut -d "=" -f2 | tr -d '"');
PORT=$(grep -e "^PORT=" .env | cut -d "=" -f2 | tr -d '"');
TOKENIZATION_PORT=$(grep -e "^TOKENIZATION_PORT=" .env | cut -d "=" -f2 | tr -d '"');
TX_WAIT_TIME=5
URL=http://localhost:$PORT
TOKENIZATION_URL=http://localhost:$TOKENIZATION_PORT
# TX_WAIT_TIME=30
# URL=https://zero-api-staging.herokuapp.com
# TOKENIZATION_URL=https://zero-tokenization-staging.herokuapp.com
echo
echo "creating sellerId=00000000-0000-0000-0000-000000000001"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/sellers" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"id": "00000000-0000-0000-0000-000000000001",
"name": "Monsoon Carbon",
"addressLine1": "Mt Arrakis 42, Dune plains",
"addressLine2": "Aix en Provence, 12345, France",
"contactPerson": "Paul Atreides"
}'
echo
echo "creating buyerId=00000000-0000-0000-0000-000000000002"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/buyers" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"id": "00000000-0000-0000-0000-000000000002",
"name": "-"
}'
echo
echo "creating buyerId=00000000-0000-0000-0000-000000000003"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/buyers" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"id": "00000000-0000-0000-0000-000000000003",
"name": "-"
}'
echo
echo "creating nodeId=f00001 for buyerId=00000000-0000-0000-0000-000000000002"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/nodes" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"id": "f00001",
"buyerId": "00000000-0000-0000-0000-000000000002",
"country": "CN",
"region": "BJ"
}'
echo
echo "creating nodeId=f00002 for buyerId=00000000-0000-0000-0000-000000000003"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/nodes" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"id": "f00002",
"buyerId": "00000000-0000-0000-0000-000000000003"
}'
echo
echo "creating certificates"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/certificates" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '[{
"id": "00000000-0000-0000-0000-000000000333",
"generatorName": "Solar 1 - Non Bua Lampon",
"generatorId": "NA",
"initialSellerId": "00000000-0000-0000-0000-000000000001",
"region": "north_china",
"country": "CN",
"energySource": "WIND",
"productType": "IREC",
"generationStart": "2020-11-01T00:00:00.000Z",
"generationEnd": "2021-06-01T23:59:59.999Z",
"energyWh": "3000000",
"nameplateCapacityW": 12000
},{
"id": "00000000-0000-0000-0000-000000000777",
"generatorName": "Solar 1 - Non Bua Lampon",
"generatorId": "NA",
"initialSellerId": "00000000-0000-0000-0000-000000000001",
"region": "north_china",
"country": "CN",
"energySource": "WIND",
"productType": "IREC",
"generationStart": "2021-06-02T00:00:00.000Z",
"generationEnd": "2021-06-30T23:59:59.999Z",
"energyWh": "7000000",
"nameplateCapacityW": 400000000,
"redemptionDate": "2020-01-01T00:00:00.000Z"
}]'
echo
echo "generating a batch ID"
BATCH_ID=$(curl -w "\n" -s -X 'GET' "$TOKENIZATION_URL/api/batch/id/generate" -H "X-API-KEY: $X_API_KEY" -H 'Content-Type: application/json')
echo "batch ID: $BATCH_ID"
echo
echo "creating a batch off-chain"
curl -w "\n" -s -X 'POST' "$URL/api/partners/filecoin/batch/$BATCH_ID" -H "X-API-KEY: $X_API_KEY" -H 'Content-Type: application/json'
echo "created off-chain batch: $BATCH_ID"
echo
echo "setting the redemption statement"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/batch/$BATCH_ID/redemption-statement" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d @- <<END;
{
"redemptionStatementId": "bafkreigxldrh3lo2spyg424ga4r7srss4f4umm3v7njljod7qvyjtvlg7e",
"totalVolume": "3000000"
}
END
echo
echo "waiting $TX_WAIT_TIME seconds for redemption statement to be mined..."
sleep $TX_WAIT_TIME
echo
echo "minting certificates on-chain"
MINT_TX_HASH=$(curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/batch/$BATCH_ID/mint" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"certificateIds": ["00000000-0000-0000-0000-000000000333"]
}')
echo "Triggered the minting transaction $MINT_TX_HASH"
echo
echo "waiting $TX_WAIT_TIME seconds for the minting transaction to be mined $MINT_TX_HASH..."
sleep $TX_WAIT_TIME
echo
echo "detecting and attaching minted certificates"
curl -w "\n" -s -X 'PATCH' \
"$URL/api/partners/filecoin/batch/attach/$MINT_TX_HASH" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json'
echo "Successfully attached certificates for $MINT_TX_HASH"
echo
echo "creating a contract"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/contracts" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '[{
"id": "00000000-0000-0000-0000-000000666666",
"productType": "IREC",
"energySources": [
"SOLAR",
"WIND"
],
"region": "EU",
"countries": ["DE", "HR"],
"contractDate": "2020-11-01T00:00:00.000Z",
"deliveryDate": "2021-06-01T23:59:59.999Z",
"reportingStart": "2020-11-01T00:00:00.000Z",
"reportingEnd": "2021-06-01T23:59:59.999Z",
"timezoneOffset": 180,
"volume": "4000000000000",
"buyerId": "00000000-0000-0000-0000-000000000002",
"sellerId": "00000000-0000-0000-0000-000000000001",
"filecoinNodeId": "f00001",
"label": "GREEN_E_ENERGY"
}]'
echo
echo "deploying the contract on-chain"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/contracts/on-chain/deploy" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '["00000000-0000-0000-0000-000000666666"]'
echo
echo "waiting $TX_WAIT_TIME seconds for the on-chain deployment transaction to be mined..."
sleep $TX_WAIT_TIME
echo
echo "signing the on-chain contract"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/contracts/on-chain/sign" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '["00000000-0000-0000-0000-000000666666"]'
echo
echo "waiting $TX_WAIT_TIME seconds for the on-chain signing transaction to be mined..."
sleep $TX_WAIT_TIME
echo
echo "creating purchases"
curl -w "\n" -s -X 'POST' \
"$URL/api/partners/filecoin/purchases" \
-H "X-API-KEY: $X_API_KEY" \
-H 'Content-Type: application/json' \
-d '[{
"id": "00000000-0000-0000-0000-000000444444",
"certificateId": "00000000-0000-0000-0000-000000000333",
"sellerId": "00000000-0000-0000-0000-000000000001",
"buyerId": "00000000-0000-0000-0000-000000000002",
"filecoinNodeId": "f00001",
"contractId": "00000000-0000-0000-0000-000000666666",
"reportingStart": "2020-01-01T00:00:00.000Z",
"reportingEnd": "2020-12-31T23:59:59.999Z",
"recsSoldWh": "2000000"
}]'