Skip to content

Commit e897830

Browse files
nooxxloicttn
authored andcommitted
wip
1 parent baba4c4 commit e897830

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

examples/ada.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const f = async () => {
2323
'376acfff-e35d-4b7c-90da-c6acb8ea7197',
2424
'addr_test1qpy358g8glafrucevf0rjpmzx2k5esn5uvjh7dzuakpdhv4g2egyt3y3qw6jrguz0lmyhxygjdg2ytaf5z6ueaety7dsmpcee5',
2525
);
26-
const txSigned = await k.ada.sign('vault1', tx);
27-
const hash = await k.ada.broadcast(txSigned);
28-
console.log(hash);
26+
// const txSigned = await k.ada.sign('vault1', tx);
27+
// const hash = await k.ada.broadcast(txSigned);
28+
// console.log(hash);
2929
} catch (err){
3030
console.log(err);
3131
}

src/services/ada.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ export class AdaService extends Service {
3434
walletAddress: string,
3535
options?: AdaStakeOptions,
3636
): Promise<Transaction> {
37+
const poolHash = this.testnet ? '3496527c1e1b20d56cc9d4e5615c76ba2421ad3f13e2561a1ad4d6c6' : '78da8fa2f5089964963a0ab7ad1402e8c656f203bef622cf9f5ee3c6';
38+
const wasmWalletAddress = CardanoWasm.Address.from_bech32(walletAddress);
39+
const baseWalletAddress = CardanoWasm.BaseAddress.from_address(wasmWalletAddress);
3740

41+
if(!baseWalletAddress){
42+
throw new Error('Could not generate base wallet address');
43+
44+
}
3845
let utxo: UTXO = [];
3946
try {
4047
utxo = await this.client.addressesUtxosAll(walletAddress);
@@ -75,13 +82,17 @@ export class AdaService extends Service {
7582
const ttl = currentSlot + 7200;
7683
txBuilder.set_ttl(ttl);
7784

85+
const addresses = await this.client.addresses(walletAddress);
86+
87+
// Add output
88+
txBuilder.add_output(
89+
CardanoWasm.TransactionOutput.new(
90+
wasmWalletAddress,
91+
CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(addresses.amount[0].quantity.toString())),
92+
),
93+
);
94+
7895
// Add delegation (stake registration + stake delegation certificates)
79-
const poolHash = this.testnet ? '3496527c1e1b20d56cc9d4e5615c76ba2421ad3f13e2561a1ad4d6c6' : '78da8fa2f5089964963a0ab7ad1402e8c656f203bef622cf9f5ee3c6';
80-
const wasmWalletAddress = CardanoWasm.Address.from_bech32(walletAddress);
81-
const baseWalletAddress = CardanoWasm.BaseAddress.from_address(wasmWalletAddress);
82-
if(!baseWalletAddress){
83-
throw new Error('Could not generate base wallet address');
84-
}
8596
const poolKeyHash = CardanoWasm.Ed25519KeyHash.from_hex(poolHash);
8697
const stakeCredentials = baseWalletAddress.stake_cred();
8798
const certificates = CardanoWasm.Certificates.new();

0 commit comments

Comments
 (0)