mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-09-18 11:44:42 -04:00
monero node api signature changes, still need to change logic
This commit is contained in:
parent
a5c40d3a9b
commit
14a15b6444
2 changed files with 31 additions and 20 deletions
|
@ -5,7 +5,7 @@ import {HavenoDaemon} from "./HavenoDaemon";
|
|||
import {HavenoUtils} from "./utils/HavenoUtils";
|
||||
import * as grpcWeb from 'grpc-web';
|
||||
import {MarketPriceInfo, NotificationMessage, OfferInfo, TradeInfo, UrlConnection, XmrBalanceInfo} from './protobuf/grpc_pb'; // TODO (woodser): better names; haveno_grpc_pb, haveno_pb
|
||||
import {Attachment, DisputeResult, PaymentMethod, PaymentAccount} from './protobuf/pb_pb';
|
||||
import {Attachment, DisputeResult, PaymentMethod, PaymentAccount, MoneroNodeSettings} from './protobuf/pb_pb';
|
||||
import {XmrDestination, XmrTx, XmrIncomingTransfer, XmrOutgoingTransfer} from './protobuf/grpc_pb';
|
||||
import AuthenticationStatus = UrlConnection.AuthenticationStatus;
|
||||
import OnlineStatus = UrlConnection.OnlineStatus;
|
||||
|
@ -470,7 +470,7 @@ test("Can start and stop local Monero node", async() => {
|
|||
let err: any;
|
||||
try {
|
||||
// ensure stopped local Monero node
|
||||
let isMoneroNodeStarted = await alice.isMoneroNodeStarted();
|
||||
let isMoneroNodeStarted = await alice.isMoneroNodeRunning();
|
||||
if (isMoneroNodeStarted) {
|
||||
await alice.stopMoneroNode();
|
||||
}
|
||||
|
@ -481,15 +481,14 @@ test("Can start and stop local Monero node", async() => {
|
|||
assert(await alice.isConnectedToMonero());
|
||||
testConnection(connection!, monerodUrl1, OnlineStatus.ONLINE, AuthenticationStatus.AUTHENTICATED, 1);
|
||||
|
||||
let username = "testuser";
|
||||
let password = "testpw123";
|
||||
let settings = new MoneroNodeSettings();
|
||||
|
||||
// check node start errors are handled
|
||||
srv = net.createServer();
|
||||
await listenPort(srv, 58081);
|
||||
try {
|
||||
console.log("Starting node with error");
|
||||
await alice.startMoneroNode(username, password);
|
||||
await alice.startMoneroNode(settings);
|
||||
throw new Error('should have thrown');
|
||||
} catch (err) {
|
||||
if (!err.message.startsWith("Failed to start monerod:")) throw new Error("Unexpected error: " + err.message);
|
||||
|
@ -498,17 +497,17 @@ test("Can start and stop local Monero node", async() => {
|
|||
|
||||
// check successful node start
|
||||
console.log("Starting node with success");
|
||||
await alice.startMoneroNode(username, password);
|
||||
await alice.startMoneroNode(settings);
|
||||
|
||||
// expect already running error
|
||||
try {
|
||||
await alice.startMoneroNode(username, password);
|
||||
await alice.startMoneroNode(settings);
|
||||
throw new Error('should have thrown');
|
||||
} catch (err) {
|
||||
if (err.message !== "Monero node already running") throw new Error("Unexpected error: " + err.message);
|
||||
}
|
||||
|
||||
isMoneroNodeStarted = await alice.isMoneroNodeStarted();
|
||||
isMoneroNodeStarted = await alice.isMoneroNodeRunning();
|
||||
assert(isMoneroNodeStarted);
|
||||
|
||||
// no longer using connection
|
||||
|
@ -520,7 +519,7 @@ test("Can start and stop local Monero node", async() => {
|
|||
assert(balance);
|
||||
|
||||
await alice.stopMoneroNode();
|
||||
isMoneroNodeStarted = await alice.isMoneroNodeStarted();
|
||||
isMoneroNodeStarted = await alice.isMoneroNodeRunning();
|
||||
assert(!isMoneroNodeStarted);
|
||||
|
||||
// check restored connection
|
||||
|
|
|
@ -2,8 +2,8 @@ import {HavenoUtils} from "./utils/HavenoUtils";
|
|||
import {TaskLooper} from "./utils/TaskLooper";
|
||||
import * as grpcWeb from 'grpc-web';
|
||||
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, GetNewDepositSubaddressRequest, GetNewDepositSubaddressReply, 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} from './protobuf/grpc_pb';
|
||||
import {PaymentMethod, PaymentAccount, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage} from './protobuf/pb_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, GetNewDepositSubaddressRequest, GetNewDepositSubaddressReply, 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';
|
||||
|
||||
const console = require('console');
|
||||
|
||||
|
@ -599,27 +599,39 @@ class HavenoDaemon {
|
|||
/**
|
||||
* Returns whether daemon is running a local monero node.
|
||||
*/
|
||||
async isMoneroNodeStarted(): Promise<boolean> {
|
||||
async isMoneroNodeRunning(): Promise<boolean> {
|
||||
let that = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
that._moneroNodeClient.isMoneroNodeStarted(new StartMoneroNodeRequest(), {password: that._password}, function(err: grpcWeb.RpcError, reply: IsMoneroNodeStartedReply) {
|
||||
that._moneroNodeClient.isMoneroNodeRunning(new IsMoneroNodeRunningRequest(), {password: that._password}, function(err: grpcWeb.RpcError, response: IsMoneroNodeRunningReply) {
|
||||
if (err) reject(err);
|
||||
else resolve(reply.getIsRunning());
|
||||
else resolve(response.getIsRunning());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current local monero node settings.
|
||||
*/
|
||||
async getMoneroNodeSettings(): Promise<MoneroNodeSettings> {
|
||||
let that = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
let request = new GetMoneroNodeSettingsRequest();
|
||||
that._moneroNodeClient.getMoneroNodeSettings(request, {password: that._password}, function(err: grpcWeb.RpcError, response: GetMoneroNodeSettingsReply) {
|
||||
if (err) reject(err);
|
||||
else resolve(response.getSettings()!);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the local monero node.
|
||||
* @param {string} rcpUsername - rpc username
|
||||
* @param {string} rcpPassword - rpc password
|
||||
*
|
||||
* @param {MoneroNodeSettings} settings - the settings to start the local node with
|
||||
*/
|
||||
async startMoneroNode(rcpUsername: string, rcpPassword: string): Promise<void> {
|
||||
async startMoneroNode(settings: MoneroNodeSettings): Promise<void> {
|
||||
let that = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
let request = new StartMoneroNodeRequest()
|
||||
.setRpcUsername(rcpUsername)
|
||||
.setRpcPassword(rcpPassword);
|
||||
let request = new StartMoneroNodeRequest().setSettings(settings);
|
||||
that._moneroNodeClient.startMoneroNode(request, {password: that._password}, function(err: grpcWeb.RpcError) {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue