-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to deregistration stake raw transaction #651
Comments
this code for preprod env. Also i check with new address, where i stake and unstake works fine. |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, i have some issue with input and outputs.
After submitting i have an issue
The text was updated successfully, but these errors were encountered: