mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-07-23 15:00:43 -04:00
support sweeping funds, relay multiple txs
This commit is contained in:
parent
9b2e96eeea
commit
48e14877e3
2 changed files with 27 additions and 5 deletions
|
@ -1084,7 +1084,7 @@ test("Has a Monero wallet (Test, CI)", async () => {
|
||||||
testTx(tx, {isCreatedTx: true});
|
testTx(tx, {isCreatedTx: true});
|
||||||
|
|
||||||
// relay withdraw tx
|
// relay withdraw tx
|
||||||
const txHash = await user1.relayXmrTx(tx.getMetadata());
|
const txHash = (await user1.relayXmrTxs([tx.getMetadata()]))[0];
|
||||||
expect(txHash.length).toEqual(64);
|
expect(txHash.length).toEqual(64);
|
||||||
await wait(TestConfig.trade.walletSyncPeriodMs * 2); // wait for wallet to sync relayed tx
|
await wait(TestConfig.trade.walletSyncPeriodMs * 2); // wait for wallet to sync relayed tx
|
||||||
|
|
||||||
|
@ -1099,11 +1099,18 @@ test("Has a Monero wallet (Test, CI)", async () => {
|
||||||
|
|
||||||
// relay invalid tx
|
// relay invalid tx
|
||||||
try {
|
try {
|
||||||
await user1.relayXmrTx("invalid tx metadata");
|
await user1.relayXmrTxs(["invalid tx metadata"]);
|
||||||
throw new Error("Cannot relay invalid tx metadata");
|
throw new Error("Cannot relay invalid tx metadata");
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.message !== "Failed to parse hex.") throw new Error("Unexpected error: " + err.message);
|
if (err.message !== "Failed to parse hex.") throw new Error("Unexpected error: " + err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create sweep txs
|
||||||
|
let sweepTxs = await user1.createXmrSweepTxs(await user1.getXmrNewSubaddress());
|
||||||
|
assert(sweepTxs.length > 0);
|
||||||
|
for (const sweepTx of sweepTxs) {
|
||||||
|
testTx(sweepTx, {isCreatedTx: true});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can get balances (Test, CI, sanity check)", async () => {
|
test("Can get balances (Test, CI, sanity check)", async () => {
|
||||||
|
|
|
@ -21,7 +21,7 @@ import HavenoUtils from "./utils/HavenoUtils";
|
||||||
import TaskLooper from "./utils/TaskLooper";
|
import TaskLooper from "./utils/TaskLooper";
|
||||||
import type * as grpcWeb from "grpc-web";
|
import type * as grpcWeb from "grpc-web";
|
||||||
import { GetTradeStatisticsClient, GetVersionClient, AccountClient, XmrConnectionsClient, DisputesClient, DisputeAgentsClient, NotificationsClient, WalletsClient, PriceClient, OffersClient, PaymentAccountsClient, TradesClient, ShutdownServerClient, XmrNodeClient } from './protobuf/GrpcServiceClientPb';
|
import { GetTradeStatisticsClient, GetVersionClient, AccountClient, XmrConnectionsClient, DisputesClient, DisputeAgentsClient, NotificationsClient, WalletsClient, PriceClient, OffersClient, PaymentAccountsClient, TradesClient, ShutdownServerClient, XmrNodeClient } from './protobuf/GrpcServiceClientPb';
|
||||||
import { GetTradeStatisticsRequest, GetTradeStatisticsReply, GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, UnregisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, ValidateFormFieldRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, DeletePaymentAccountRequest, DeletePaymentAccountReply, PostOfferRequest, PostOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetXmrPrimaryAddressRequest, GetXmrPrimaryAddressReply, GetXmrNewSubaddressRequest, GetXmrNewSubaddressReply, ConfirmPaymentSentRequest, ConfirmPaymentReceivedRequest, CompleteTradeRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, RelayXmrTxRequest, RelayXmrTxReply, CreateAccountRequest, AccountExistsRequest, AccountExistsReply, DeleteAccountRequest, OpenAccountRequest, IsAccountOpenRequest, IsAccountOpenReply, CloseAccountRequest, ChangePasswordRequest, BackupAccountRequest, BackupAccountReply, RestoreAccountRequest, StopRequest, NotificationMessage, RegisterNotificationListenerRequest, SendNotificationRequest, UrlConnection, AddConnectionRequest, RemoveConnectionRequest, GetConnectionRequest, GetConnectionsRequest, SetConnectionRequest, CheckConnectionRequest, CheckConnectionsReply, CheckConnectionsRequest, StartCheckingConnectionRequest, StopCheckingConnectionRequest, GetBestConnectionRequest, SetAutoSwitchRequest, GetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartXmrNodeRequest, StopXmrNodeRequest, IsXmrNodeOnlineRequest, IsXmrNodeOnlineReply, GetXmrNodeSettingsRequest, GetXmrNodeSettingsReply } from "./protobuf/grpc_pb";
|
import { GetTradeStatisticsRequest, GetTradeStatisticsReply, GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, UnregisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, ValidateFormFieldRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, DeletePaymentAccountRequest, DeletePaymentAccountReply, PostOfferRequest, PostOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetXmrPrimaryAddressRequest, GetXmrPrimaryAddressReply, GetXmrNewSubaddressRequest, GetXmrNewSubaddressReply, ConfirmPaymentSentRequest, ConfirmPaymentReceivedRequest, CompleteTradeRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, CreateXmrSweepTxsRequest, CreateXmrSweepTxsReply, RelayXmrTxsRequest, RelayXmrTxsReply, CreateAccountRequest, AccountExistsRequest, AccountExistsReply, DeleteAccountRequest, OpenAccountRequest, IsAccountOpenRequest, IsAccountOpenReply, CloseAccountRequest, ChangePasswordRequest, BackupAccountRequest, BackupAccountReply, RestoreAccountRequest, StopRequest, NotificationMessage, RegisterNotificationListenerRequest, SendNotificationRequest, UrlConnection, AddConnectionRequest, RemoveConnectionRequest, GetConnectionRequest, GetConnectionsRequest, SetConnectionRequest, CheckConnectionRequest, CheckConnectionsReply, CheckConnectionsRequest, StartCheckingConnectionRequest, StopCheckingConnectionRequest, GetBestConnectionRequest, SetAutoSwitchRequest, GetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartXmrNodeRequest, StopXmrNodeRequest, IsXmrNodeOnlineRequest, IsXmrNodeOnlineReply, GetXmrNodeSettingsRequest, GetXmrNodeSettingsReply } from "./protobuf/grpc_pb";
|
||||||
import { TradeStatistics3, OfferDirection, PaymentMethod, PaymentAccountForm, PaymentAccountFormField, PaymentAccount, PaymentAccountPayload, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, XmrNodeSettings } from "./protobuf/pb_pb";
|
import { TradeStatistics3, OfferDirection, PaymentMethod, PaymentAccountForm, PaymentAccountFormField, PaymentAccount, PaymentAccountPayload, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, XmrNodeSettings } from "./protobuf/pb_pb";
|
||||||
|
|
||||||
|
|
||||||
|
@ -783,6 +783,7 @@ export default class HavenoClient {
|
||||||
/**
|
/**
|
||||||
* Create but do not relay a transaction to send funds from the Monero wallet.
|
* Create but do not relay a transaction to send funds from the Monero wallet.
|
||||||
*
|
*
|
||||||
|
* @param {XmrDestination[]} destinations - the destinations to send funds to
|
||||||
* @return {XmrTx} the created transaction
|
* @return {XmrTx} the created transaction
|
||||||
*/
|
*/
|
||||||
async createXmrTx(destinations: XmrDestination[]): Promise<XmrTx> {
|
async createXmrTx(destinations: XmrDestination[]): Promise<XmrTx> {
|
||||||
|
@ -793,14 +794,28 @@ export default class HavenoClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create but do not relay transactions to sweep all funds from the Monero wallet.
|
||||||
|
*
|
||||||
|
* @param {string} address - the address to sweep funds to
|
||||||
|
* @return {XmrTx} the created transactions
|
||||||
|
*/
|
||||||
|
async createXmrSweepTxs(address: string): Promise<XmrTx[]> {
|
||||||
|
try {
|
||||||
|
return (await this._walletsClient.createXmrSweepTxs(new CreateXmrSweepTxsRequest().setAddress(address), {password: this._password})).getTxsList()!;
|
||||||
|
} catch (e: any) {
|
||||||
|
throw new HavenoError(e.message, e.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relay a previously created transaction to send funds from the Monero wallet.
|
* Relay a previously created transaction to send funds from the Monero wallet.
|
||||||
*
|
*
|
||||||
* @return {string} the hash of the relayed transaction
|
* @return {string} the hash of the relayed transaction
|
||||||
*/
|
*/
|
||||||
async relayXmrTx(metadata: string): Promise<string> {
|
async relayXmrTxs(metadatas: string[]): Promise<string[]> {
|
||||||
try {
|
try {
|
||||||
return (await this._walletsClient.relayXmrTx(new RelayXmrTxRequest().setMetadata(metadata), {password: this._password})).getHash();
|
return (await this._walletsClient.relayXmrTxs(new RelayXmrTxsRequest().setMetadatasList(metadatas), {password: this._password})).getHashesList();
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
throw new HavenoError(e.message, e.code);
|
throw new HavenoError(e.message, e.code);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue