mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2024-12-25 07:19:29 -05:00
support getXmrPrimaryAddress(), getXmrNewSubaddress()
This commit is contained in:
parent
34d195c307
commit
e9995566cd
@ -599,6 +599,10 @@ test("Has a Monero wallet", async () => {
|
|||||||
const seed = await alice.getXmrSeed();
|
const seed = await alice.getXmrSeed();
|
||||||
await MoneroUtils.validateMnemonic(seed);
|
await MoneroUtils.validateMnemonic(seed);
|
||||||
|
|
||||||
|
// get primary address
|
||||||
|
const primaryAddress = await alice.getXmrPrimaryAddress();
|
||||||
|
await MoneroUtils.validateAddress(primaryAddress, MoneroNetworkType.STAGENET);
|
||||||
|
|
||||||
// wait for alice to have unlocked balance
|
// wait for alice to have unlocked balance
|
||||||
const tradeAmount = BigInt("250000000000");
|
const tradeAmount = BigInt("250000000000");
|
||||||
await waitForUnlockedBalance(tradeAmount * BigInt("2"), alice);
|
await waitForUnlockedBalance(tradeAmount * BigInt("2"), alice);
|
||||||
@ -615,14 +619,14 @@ test("Has a Monero wallet", async () => {
|
|||||||
testTx(tx, {isCreatedTx: false});
|
testTx(tx, {isCreatedTx: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
// get new deposit addresses
|
// get new subaddresses
|
||||||
for (let i = 0; i < 0; i++) {
|
for (let i = 0; i < 0; i++) {
|
||||||
const address = await alice.getNewDepositAddress();
|
const address = await alice.getXmrNewSubaddress();
|
||||||
await MoneroUtils.validateAddress(address, MoneroNetworkType.STAGNET);
|
await MoneroUtils.validateAddress(address, MoneroNetworkType.STAGNET);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create withdraw tx
|
// create withdraw tx
|
||||||
const destination = new XmrDestination().setAddress(await alice.getNewDepositAddress()).setAmount("100000000000");
|
const destination = new XmrDestination().setAddress(await alice.getXmrNewSubaddress()).setAmount("100000000000");
|
||||||
let tx = await alice.createXmrTx([destination]);
|
let tx = await alice.createXmrTx([destination]);
|
||||||
testTx(tx, {isCreatedTx: true});
|
testTx(tx, {isCreatedTx: true});
|
||||||
|
|
||||||
@ -1838,7 +1842,7 @@ async function waitForUnlockedBalance(amount: bigint, ...wallets: any[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getDepositAddress(): Promise<string> {
|
async getDepositAddress(): Promise<string> {
|
||||||
if (this._wallet instanceof HavenoClient) return await this._wallet.getNewDepositAddress();
|
if (this._wallet instanceof HavenoClient) return await this._wallet.getXmrNewSubaddress();
|
||||||
else return (await this._wallet.createSubaddress()).getAddress();
|
else return (await this._wallet.createSubaddress()).getAddress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,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 { GetVersionClient, AccountClient, MoneroConnectionsClient, DisputesClient, DisputeAgentsClient, NotificationsClient, WalletsClient, PriceClient, OffersClient, PaymentAccountsClient, TradesClient, ShutdownServerClient, MoneroNodeClient } from './protobuf/GrpcServiceClientPb';
|
import { GetVersionClient, AccountClient, MoneroConnectionsClient, DisputesClient, DisputeAgentsClient, NotificationsClient, WalletsClient, PriceClient, OffersClient, PaymentAccountsClient, TradesClient, ShutdownServerClient, MoneroNodeClient } from './protobuf/GrpcServiceClientPb';
|
||||||
import { GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, CreateOfferRequest, CreateOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetNewDepositAddressRequest, GetNewDepositAddressReply, ConfirmPaymentStartedRequest, ConfirmPaymentReceivedRequest, 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, StartCheckingConnectionsRequest, StopCheckingConnectionsRequest, GetBestAvailableConnectionRequest, SetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestAvailableConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartMoneroNodeRequest, StopMoneroNodeRequest, IsMoneroNodeRunningRequest, IsMoneroNodeRunningReply, GetMoneroNodeSettingsRequest, GetMoneroNodeSettingsReply } from "./protobuf/grpc_pb";
|
import { GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, CreateOfferRequest, CreateOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetXmrPrimaryAddressRequest, GetXmrPrimaryAddressReply, GetXmrNewSubaddressRequest, GetXmrNewSubaddressReply, ConfirmPaymentStartedRequest, ConfirmPaymentReceivedRequest, 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, StartCheckingConnectionsRequest, StopCheckingConnectionsRequest, GetBestAvailableConnectionRequest, SetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestAvailableConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartMoneroNodeRequest, StopMoneroNodeRequest, IsMoneroNodeRunningRequest, IsMoneroNodeRunningReply, GetMoneroNodeSettingsRequest, GetMoneroNodeSettingsReply } from "./protobuf/grpc_pb";
|
||||||
import { PaymentMethod, PaymentAccount, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, MoneroNodeSettings } from "./protobuf/pb_pb";
|
import { PaymentMethod, PaymentAccount, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, MoneroNodeSettings } from "./protobuf/pb_pb";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -677,20 +677,34 @@ export default class HavenoClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the primary address of the Monero wallet.
|
||||||
|
*
|
||||||
|
* @return {string} the primary address of the Monero wallet
|
||||||
|
*/
|
||||||
|
async getXmrPrimaryAddress(): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._walletsClient.getXmrPrimaryAddress(new GetXmrPrimaryAddressRequest(), {password: this._password}, function(err: grpcWeb.RpcError, response: GetXmrPrimaryAddressReply) {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(response.getPrimaryAddress());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a new subaddress in the Monero wallet to receive deposits.
|
* Get a new subaddress in the Monero wallet to receive deposits.
|
||||||
*
|
*
|
||||||
* @return {string} the deposit address (a subaddress in the Haveno wallet)
|
* @return {string} the deposit address (a subaddress in the Haveno wallet)
|
||||||
*/
|
*/
|
||||||
async getNewDepositAddress(): Promise<string> {
|
async getXmrNewSubaddress(): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._walletsClient.getNewDepositAddress(new GetNewDepositAddressRequest(), {password: this._password}, function(err: grpcWeb.RpcError, response: GetNewDepositAddressReply) {
|
this._walletsClient.getXmrNewSubaddress(new GetXmrNewSubaddressRequest(), {password: this._password}, function(err: grpcWeb.RpcError, response: GetXmrNewSubaddressReply) {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
else resolve(response.getSubaddress());
|
else resolve(response.getSubaddress());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all transactions in the Monero wallet.
|
* Get all transactions in the Monero wallet.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user