-
Notifications
You must be signed in to change notification settings - Fork 0
/
plutusTxService.js
285 lines (235 loc) · 8.78 KB
/
plutusTxService.js
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
const CoinSelection = require('./util/coinSelection');
// const CCTxBuilder = require('./plutusTxBuilder');
const CCTxBuilder = require('./plutusTxBuilderV2');
const NftCCTxBuilder = require('./plutusNftTxBuilder');
const UtxosManager = require('./utxosManager');
class PlutusTxService {
constructor(chainConnector, scriptRefOwnerAddr, logger, bMainnet) {
this.chainConnector = chainConnector;
this.coinSelectionInst = new CoinSelection();
this.scriptRefOwnerAddr = scriptRefOwnerAddr;
this.logger = logger;
this.bMainnet = bMainnet;
}
async init() {
/* Modify By NFT Program:
add nft tx builder object
*/
this.utxosManagerObj = new UtxosManager(this.chainConnector,
this.logger,
this.bMainnet);
let ret = await this.utxosManagerObj.init();
if (false === ret) {
return false;
}
/* Modify By NFT Program:
add nft tx builder object
*/
this.nftCCTxBuilderObj = new NftCCTxBuilder(this.chainConnector,
this.scriptRefOwnerAddr,
this.utxosManagerObj,
this.logger,
this.bMainnet);
await this.nftCCTxBuilderObj.init();
// this.ccTxBuilderObj = new CCTxBuilder(this.chainConnector,
// this.coinSelectionInst,
// this.scriptRefOwnerAddr,
// logger,
// bMainnet);
// await this.ccTxBuilderObj.init();
this.ccTxBuilderObj = new CCTxBuilder(this.chainConnector,
this.scriptRefOwnerAddr,
this.utxosManagerObj,
this.logger,
this.bMainnet);
await this.ccTxBuilderObj.init();
return true;
}
// to get cardano-side cross-chain locker address
getLockerScAddress(bNftTask = false) {
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
return this.nftCCTxBuilderObj.getLockerScAddress();
}
return this.ccTxBuilderObj.getLockerScAddress();
}
// to get treasury group address
getNFTRefHolderScript() {
return this.nftCCTxBuilderObj.getNFTRefHolderScript();
}
// Part 1: cross-chain process
// to build cross-chain tx
async buildSignedTx(basicArgs, internalSignFunc, partialRedeemerArgs, bNftTask = false) {
/* Modify By NFT Program:
need to add bNftCCTx? or add txType to justify?
*/
if (bNftTask) {
let ret = await this.nftCCTxBuilderObj.buildSignedTx(basicArgs, internalSignFunc, partialRedeemerArgs);
return ret;
}
let ret = await this.ccTxBuilderObj.buildSignedTx(basicArgs, internalSignFunc, partialRedeemerArgs);
return ret;
}
// to generate hash by redeem proof info
genRedeemProofHash(proofInfo, bNftTask = false) {
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let ret = this.nftCCTxBuilderObj.genRedeemProofHash(proofInfo);
return ret;
}
let ret = this.ccTxBuilderObj.genRedeemProofHash(proofInfo);
return ret;
}
// to generate hash by token redeem proof info
genTokenRedeemProofHash(proofInfo, bNftTask = false) {
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let ret = this.nftCCTxBuilderObj.genTokenRedeemProofHash(proofInfo);
return ret;
}
let ret = this.ccTxBuilderObj.genTokenRedeemProofHash(proofInfo);
return ret;
}
// Part 2: utxos balanced process
// to mark asset type that needs balanced
markPendingBalancedAsset(address, assetUnit) {
this.ccTxBuilderObj.markBalancedAsset(address, assetUnit);
return;
}
// to build, sign and submit utxos-balanced tx
async tryUtxosBalanced(internalSignFunc, paymentInfo, address) {
return await this.ccTxBuilderObj.tryUtxosBalanced(internalSignFunc, paymentInfo, address);
}
// Part 3: manual process
// to get&decode tx redeemers based on txInfo
async getRedeemerFromCBOR(txInfo, bNftTask = false) {
if (undefined === txInfo.redeemers) {
return undefined;
}
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let redeemerData = this.nftCCTxBuilderObj.deCodeTxRedeemersCbor(txInfo, false);
console.log("\n\ngetRedeemerFromCBOR...nft: ", redeemerData);
return redeemerData;
}
let redeemerData = await this.ccTxBuilderObj.deCodeTxRedeemersCbor(txInfo, false);
console.log("\n\ngetRedeemerFromCBOR: ", redeemerData);
return redeemerData;
}
// to get&decode mint-tx redeemers based on txInfo
async getTokenRedeemerFromCBOR(txInfo, bNftTask = false) {
if (undefined === txInfo.redeemers) {
return undefined;
}
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let redeemerData = this.nftCCTxBuilderObj.deCodeTxRedeemersCbor(txInfo, true);
console.log("\n\ngetRedeemerFromCBOR...nft: ", redeemerData);
return redeemerData;
}
let redeemerData = await this.ccTxBuilderObj.deCodeTxRedeemersCbor(txInfo, true);
// let bMintTx = true;
// let redeemerData = await this.ccTxBuilderObj.deCodeTxRedeemersCbor(txInfo, bMintTx);
console.log("\n\ngetTokenRedeemerFromCBOR: ", redeemerData);
return redeemerData;
}
checkIfContainTreasuryUtxo(txInputUtxos, bNftTask = false) {
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let bRet = this.nftCCTxBuilderObj.checkIfContainTreasuryUtxo(txInputUtxos);
return bRet;
}
let bRet = this.ccTxBuilderObj.checkIfContainTreasuryUtxo(txInputUtxos);
return bRet;
}
getValidPolicyId(bNftTask = false) {
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let policyId = this.nftCCTxBuilderObj.getValidPolicyId();
return policyId;
}
let policyId = this.ccTxBuilderObj.getValidPolicyId();
return policyId;
}
addressToPkhOrScriptHash(address, bNftTask = false) {
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let pkh = this.nftCCTxBuilderObj.addressToPkhOrScriptHash(address);
return pkh;
}
let pkh = this.ccTxBuilderObj.addressToPkhOrScriptHash(address);
return pkh;
}
async confirmTx(txHash, bNftTask = false) {
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
await this.nftCCTxBuilderObj.confirmTx(txHash);
return;
}
await this.ccTxBuilderObj.confirmTx(txHash);
}
revertUtxoPendingComsumedStatus(inputUtxos) {
this.ccTxBuilderObj.revertUtxoPendingComsumedStatus(inputUtxos);
// /* Modify By NFT Program:
// add nft tx builder object
// */
// this.nftCCTxBuilderObj.revertUtxoPendingComsumedStatus(inputUtxos);
}
//
async getTreasuryCheckUtxosTotalNum(bNftTask = false) {
let bMintCheck = false;
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let utxoNum = await this.nftCCTxBuilderObj.getTreasuryCheckUtxosTotalNum(bMintCheck);
return utxoNum;
}
let utxoNum = await this.ccTxBuilderObj.getTreasuryCheckUtxosTotalNum(bMintCheck);
console.log("\n\n getTreasuryCheckUtxosTotalNum: ", utxoNum);
return utxoNum;
}
//
async getMintTreasuryCheckUtxosTotalNum(bNftTask = false) {
let bMintCheck = true;
/* Modify By NFT Program:
add nft tx builder object
*/
if (bNftTask) {
let utxoNum = await this.nftCCTxBuilderObj.getTreasuryCheckUtxosTotalNum(bMintCheck);
return utxoNum;
}
let utxoNum = await this.ccTxBuilderObj.getTreasuryCheckUtxosTotalNum(bMintCheck);
console.log("\n\n getMintTreasuryCheckUtxosTotalNum: ", utxoNum);
return utxoNum;
}
async checkNFTRefAssets(refAssetHolder, refAssets) {
let ret = this.nftCCTxBuilderObj.checkNFTRefAssets(refAssetHolder, refAssets);
// true: available and no need to mint;
// false: need to mint this kind ref assets
return ret;
}
genNFTAssetName(name, typeCode) {
let ret = this.nftCCTxBuilderObj.genNFTAssetName(name, typeCode);
return ret;
}
}
module.exports = PlutusTxService;