Skip to content

Commit c0681c4

Browse files
nooxxloicttn
authored andcommitted
cleanup
1 parent af6f1eb commit c0681c4

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

src/services/ada.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs';
21
import {
32
Address,
43
BigNum,
54
Certificate,
65
Certificates,
6+
CoinSelectionStrategyCIP2,
77
Ed25519KeyHash,
8-
LinearFee, PublicKey,
8+
Ed25519Signature,
9+
hash_transaction,
10+
LinearFee,
11+
PublicKey,
912
RewardAddress,
1013
StakeCredential,
1114
StakeDelegation,
1215
StakeRegistration,
1316
Transaction,
1417
TransactionBuilder,
1518
TransactionBuilderConfigBuilder,
19+
TransactionHash,
20+
TransactionInput,
1621
TransactionOutput,
1722
TransactionOutputs,
18-
Value, Vkey, VRFVKey,
23+
TransactionUnspentOutput,
24+
TransactionUnspentOutputs,
25+
TransactionWitnessSet,
26+
Value,
27+
Vkey, Vkeywitness, Vkeywitnesses,
1928
} from '@emurgo/cardano-serialization-lib-nodejs';
20-
import { mnemonicToEntropy } from 'bip39';
2129
import { Service } from "./service";
2230
import { AdaStakeOptions, InternalAdaConfig, UTXO } from "../types/ada";
2331
import {
@@ -125,10 +133,10 @@ export class AdaService extends Service {
125133
BigNum.from_str(CARDANO_PARAMS.MIN_FEE_B),
126134
),
127135
)
128-
.pool_deposit(CardanoWasm.BigNum.from_str(CARDANO_PARAMS.POOL_DEPOSIT))
129-
.key_deposit(CardanoWasm.BigNum.from_str(CARDANO_PARAMS.KEY_DEPOSIT))
136+
.pool_deposit(BigNum.from_str(CARDANO_PARAMS.POOL_DEPOSIT))
137+
.key_deposit(BigNum.from_str(CARDANO_PARAMS.KEY_DEPOSIT))
130138
.coins_per_utxo_word(
131-
CardanoWasm.BigNum.from_str(CARDANO_PARAMS.COINS_PER_UTXO_WORD),
139+
BigNum.from_str(CARDANO_PARAMS.COINS_PER_UTXO_WORD),
132140
)
133141
.max_value_size(CARDANO_PARAMS.MAX_VALUE_SIZE)
134142
.max_tx_size(CARDANO_PARAMS.MAX_TX_SIZE)
@@ -144,29 +152,29 @@ export class AdaService extends Service {
144152
(u: any) => !u.amount.find((a: any) => a.unit !== 'lovelace'),
145153
);
146154

147-
const unspentOutputs = CardanoWasm.TransactionUnspentOutputs.new();
155+
const unspentOutputs = TransactionUnspentOutputs.new();
148156
for (const utxo of lovelaceUtxos) {
149157
const amount = utxo.amount.find(
150158
(a: any) => a.unit === 'lovelace',
151159
)?.quantity;
152160

153161
if (!amount) continue;
154162

155-
const inputValue = CardanoWasm.Value.new(
156-
CardanoWasm.BigNum.from_str(amount.toString()),
163+
const inputValue = Value.new(
164+
BigNum.from_str(amount.toString()),
157165
);
158166

159-
const input = CardanoWasm.TransactionInput.new(
160-
CardanoWasm.TransactionHash.from_bytes(Buffer.from(utxo.tx_hash, 'hex')),
167+
const input = TransactionInput.new(
168+
TransactionHash.from_bytes(Buffer.from(utxo.tx_hash, 'hex')),
161169
utxo.output_index,
162170
);
163-
const output = CardanoWasm.TransactionOutput.new(Address.from_bech32(changeAddress), inputValue);
164-
unspentOutputs.add(CardanoWasm.TransactionUnspentOutput.new(input, output));
171+
const output = TransactionOutput.new(Address.from_bech32(changeAddress), inputValue);
172+
unspentOutputs.add(TransactionUnspentOutput.new(input, output));
165173
}
166174

167175
txBuilder.add_inputs_from(
168176
unspentOutputs,
169-
CardanoWasm.CoinSelectionStrategyCIP2.LargestFirst,
177+
CoinSelectionStrategyCIP2.LargestFirst,
170178
);
171179

172180
// Outputs
@@ -247,7 +255,7 @@ export class AdaService extends Service {
247255
throw new InvalidIntegration(`Could not retrieve fireblocks signer.`);
248256
}
249257

250-
const message = CardanoWasm.hash_transaction(transaction.body()).to_hex();
258+
const message = hash_transaction(transaction.body()).to_hex();
251259

252260
const payload = {
253261
rawMessageData: {
@@ -264,15 +272,15 @@ export class AdaService extends Service {
264272

265273
const fbTx = await this.fbSigner.signWithFB(payload, this.testnet ? 'ADA_TEST' : 'ADA');
266274

267-
const pubKey = CardanoWasm.PublicKey.from_hex(fbTx.signedMessages![0].publicKey);
268-
const vKey = CardanoWasm.Vkey.new(pubKey);
269-
const signature = CardanoWasm.Ed25519Signature.from_hex(fbTx.signedMessages![0].signature.fullSig);
270-
const witnesses = CardanoWasm.TransactionWitnessSet.new();
271-
const vkeyWitnesses = CardanoWasm.Vkeywitnesses.new();
272-
const vkeyWitness = CardanoWasm.Vkeywitness.new(vKey, signature);
275+
const pubKey = PublicKey.from_hex(fbTx.signedMessages![0].publicKey);
276+
const vKey = Vkey.new(pubKey);
277+
const signature = Ed25519Signature.from_hex(fbTx.signedMessages![0].signature.fullSig);
278+
const witnesses = TransactionWitnessSet.new();
279+
const vkeyWitnesses = Vkeywitnesses.new();
280+
const vkeyWitness = Vkeywitness.new(vKey, signature);
273281
vkeyWitnesses.add(vkeyWitness);
274282
witnesses.set_vkeys(vkeyWitnesses);
275-
return CardanoWasm.Transaction.new(transaction.body(), witnesses);
283+
return Transaction.new(transaction.body(), witnesses);
276284
}
277285

278286
/**

src/types/ada.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Integrations } from "./integrations";
22
import { Responses } from '@blockfrost/blockfrost-js';
3-
import * as CardanoWasm from "@emurgo/cardano-serialization-lib-nodejs";
43

54
export type InternalAdaConfig = {
65
testnet?: boolean;
@@ -9,17 +8,6 @@ export type InternalAdaConfig = {
98

109
export type UTXO = Responses['address_utxo_content'];
1110

12-
export interface AdaAssetAmount {
13-
unit: string;
14-
quantity: string;
15-
}
16-
17-
18-
export type AdaTx = {
19-
txHash: string;
20-
txBody: CardanoWasm.TransactionBody;
21-
};
22-
2311
export type AdaStakeOptions = {
2412
poolId: string;
2513
};

0 commit comments

Comments
 (0)