Closed vladcorn closed 8 months ago
this code for preprod env. Also i check with new address, where i stake and unstake works fine. but if stake has been delegated and you use ADA after it, this code doesn't work. Any thoughts?
async createDeactivationTransaction(
data: CreateDeactivationTransactionRequest,
): Promise<CreateDeactivationTransactionResponse> {
const txBuilder = await this.createBasicTransaction();
let address = data?.paymentUserAddress;
let stakeAddress = data?.stakeUserAddress;
if (stakeAddress && !address) {
try {
const addresses = await this.blockfrostClient.accountsAddresses(stakeAddress);
address = addresses[0].address;
} catch (error) {
if (error instanceof BlockfrostServerError && error.status_code === 400) {
throw new RpcException({
code: status.INVALID_ARGUMENT,
message: error,
});
}
throw new RpcException({
code: status.INTERNAL,
error,
});
}
}
if (address && !stakeAddress) {
try {
const addresses = await this.blockfrostClient.addresses(address);
stakeAddress = addresses.stake_address;
} catch (error) {
if (error instanceof BlockfrostServerError && error.status_code === 400) {
throw new RpcException({
code: status.INVALID_ARGUMENT,
message: error,
});
}
throw new RpcException({
code: status.INTERNAL,
error,
});
}
}
const { wasmWalletAddress, baseWalletAddress } = await this.createAddresses(address);
const stakeCredentials = baseWalletAddress.stake_cred();
const certificates = Certificates.new();
const stakeDeRegistration = StakeDeregistration.new(stakeCredentials);
const stakeDeRegistrationCertificate = Certificate.new_stake_deregistration(stakeDeRegistration);
certificates.add(stakeDeRegistrationCertificate);
txBuilder.set_certs(certificates);
let utxo: Awaited<ReturnType<BlockFrostAPI['addressesUtxos']>> = [];
try {
utxo = await this.blockfrostClient.addressesUtxos(address);
} catch (error) {
if (error instanceof BlockfrostServerError && error.status_code === 404) {
throw new RpcException(`You should send ADA to ${address} to have enough funds to sent a transaction`);
} else {
throw new RpcException({
code: status.INTERNAL,
error,
});
}
}
// Filter out multi asset utxo to keep this simple
const lovelaceUtxos = utxo.filter((u) => !u.amount.find((a) => a.unit !== 'lovelace'));
const txInput = lovelaceUtxos[0];
if (!txInput) {
this.logger.warn(`Failed to find staking tx hash for ${address}`);
throw new RpcException({
code: status.NOT_FOUND,
message: 'Failed to find staking tx hash',
});
}
const txAmount = txInput.amount.find((tx) => tx.unit === 'lovelace').quantity;
txBuilder.add_input(
wasmWalletAddress,
TransactionInput.new(TransactionHash.from_hex(txInput.tx_hash), txInput.output_index),
Value.new(BigNum.from_str(txAmount)),
);
// Calculate the min fee required and send any change to an address
txBuilder.add_change_if_needed(wasmWalletAddress);
return {
hash: txBuilder.build_tx().to_hex(),
};
}
fixed with this
Hi, i have some issue with input and outputs.
After submitting i have an issue