@verii/metadata-registration 1.0.0-pre.1752076816

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const { last } = require('lodash/fp');
18
+ const { initContractClient } = require('@verii/base-contract-io');
19
+ const contractAbi = require('./contracts/verification-coupon.json');
20
+
21
+ const initVerificationCoupon = async (
22
+ { privateKey, contractAddress, rpcProvider },
23
+ context
24
+ ) => {
25
+ const { log } = context;
26
+ log.info({ privateKey, contractAddress }, 'initVerificationCoupon');
27
+
28
+ const { contractClient, pullEvents } = await initContractClient(
29
+ {
30
+ privateKey,
31
+ contractAddress,
32
+ rpcProvider,
33
+ contractAbi,
34
+ },
35
+ context
36
+ );
37
+
38
+ const isExpired = (tokenId) => {
39
+ log.info({ tokenId }, 'isExpired');
40
+ return contractClient.isExpired(tokenId);
41
+ };
42
+
43
+ const mint = async ({ toAddress, expirationTime, quantity, ownerDid }) => {
44
+ log.info({ toAddress, expirationTime, quantity, ownerDid }, 'mint');
45
+ const { traceId } = context;
46
+ const tx = await contractClient.mint(
47
+ toAddress,
48
+ Math.floor(Date.parse(expirationTime) / 1000),
49
+ quantity,
50
+ traceId,
51
+ ownerDid
52
+ );
53
+
54
+ const transactionReceipt = await tx.wait();
55
+
56
+ return last(transactionReceipt.logs).args;
57
+ };
58
+
59
+ const burn = async (tokenId, traceId, caoDid, burnerDid, burnAddress) => {
60
+ log.info({ tokenId, traceId, caoDid, burnerDid, burnAddress }, 'burn');
61
+ const tx = await contractClient.burn(
62
+ tokenId,
63
+ traceId,
64
+ caoDid,
65
+ burnerDid,
66
+ burnAddress
67
+ );
68
+
69
+ const transactionReceipt = await tx.wait();
70
+
71
+ return last(transactionReceipt.logs).args;
72
+ };
73
+
74
+ const setPermissionsAddress = async (permissionsContractAddress) => {
75
+ const tx = await contractClient.setPermissionsAddress(
76
+ permissionsContractAddress
77
+ );
78
+
79
+ return tx.wait();
80
+ };
81
+
82
+ const getCoupon = (fromAddress) => {
83
+ log.info({ fromAddress }, 'fromAddress');
84
+ return contractClient.getTokenId(fromAddress);
85
+ };
86
+
87
+ const pullMintCouponBundleEvents = pullEvents('MintCouponBundle');
88
+
89
+ const pullBurnCouponEvents = pullEvents('BurnCoupon');
90
+
91
+ return {
92
+ contractClient,
93
+ isExpired,
94
+ mint,
95
+ burn,
96
+ setPermissionsAddress,
97
+ pullMintCouponBundleEvents,
98
+ pullBurnCouponEvents,
99
+ getCoupon,
100
+ };
101
+ };
102
+
103
+ module.exports = initVerificationCoupon;