Skip to content

Commit

Permalink
chore: rename payment services
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Sep 27, 2024
1 parent f0395c6 commit 3fbfaae
Show file tree
Hide file tree
Showing 32 changed files with 248 additions and 227 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This repository is the development home to several of the tools that make it eas
- Datastore `/datastore`. Packaged "database" containing API access to crawler functions and extractor functions.
- Cloud `/cloud`. Run Ulixee tooling on a remote machine.
- Stream `/stream`. Query, transform and compose Datastores running on any machine.
- Desktop `/desktop`. Supercharge scraper script development using a Hero Replay toolset, remote Datastore viewer and Error troubleshooter.
- Desktop `/desktop`. Supercharge scraper script development using a Hero Replay toolset, remote Datastore viewer and Error troubleshooter (repository home - https://github.com/ulixee/desktop).

## Tooling

Expand Down
2 changes: 1 addition & 1 deletion client/main/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class ClientForRemote {
public port: number;
public database: string;
/**
* This variable is here just to detect when we do not think this host is a data domain
* This variable is here just to detect when we do not think this host is a domain
*/
public readonly isDnsHost: boolean;

Expand Down
4 changes: 2 additions & 2 deletions cloud/main/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ ULX_DATASTORE_STATS_HOST=# Stats Tracker Service Host
ULX_DATASTORE_REGISTRY_HOST=# Datastore Registry Service Host
ULX_STORAGE_ENGINE_HOST=# Storage Engine Service Host
ULX_REPLAY_REGISTRY_HOST=# Replays Storage/Retrieval Host
ULX_MICROPAYMENT_CHANNEL_SPEND_TRACKING_HOST=# Micropayment Channel Spend tracking Host
ULX_PAYMENT_SERVICE_HOST=# Payment Services Host
ULX_MICROPAYMENT_PROCESSOR_HOST=# Micropayment Channel Spend tracking Host
ULX_OUTBOUND_PAYMENTS_SERVICE_HOST=# Payment Services Host
ULX_DATASTORE_LOOKUP_SERVICE_HOST=

# Price per query (microgons). This is on top of Datastore pricing, used for cloud hosting.
Expand Down
17 changes: 0 additions & 17 deletions cloud/main/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ export default function cliCommands(): Command {
.argParser(parseEnvBool)
.default(false),
)
.addOption(
program
.createOption(
'--argon-payment-address <address>',
'The SS58 formatted address to send payments to.',
)
.argParser(x => parseAddress(x, 'Argon Payments Address'))
.env('ARGON_PAYMENT_ADDRESS'),
)
.addOption(
program
.createOption(
Expand Down Expand Up @@ -223,7 +214,6 @@ export default function cliCommands(): Command {
hostedServicesPort,
hostedServicesHostname,
env,
argonPaymentAddress,
argonNotaryId,
argonLocalchainPath,
argonMainchainUrl,
Expand Down Expand Up @@ -280,13 +270,6 @@ export default function cliCommands(): Command {
maxRuntimeMs: opts.maxDatastoreRuntimeMs,
waitForDatastoreCompletionOnShutdown: opts.datastoreWaitForCompletion,
adminIdentities: parseIdentities(opts.adminIdentities, 'Admin Identities'),
paymentInfo:
argonPaymentAddress && argonNotaryId
? {
address: argonPaymentAddress,
notaryId: argonNotaryId,
}
: undefined,
localchainConfig,
}),
}),
Expand Down
16 changes: 0 additions & 16 deletions coming-soon/ROADMAP-NFTs.md

This file was deleted.

6 changes: 2 additions & 4 deletions datastore/core/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ULX_DATASTORE_STATS_HOST=# Stats Tracker Service Host
ULX_DATASTORE_REGISTRY_HOST=# Datastore Registry Service Host
ULX_STORAGE_ENGINE_HOST=# Storage Engine Service Host
ULX_REPLAY_REGISTRY_HOST=# Replays Storage/Retrieval Host
CHANNELHOLDEXPIRATIONTICKS=# Micropayment Channel Spend tracking Host
ULX_PAYMENT_SERVICE_HOST=# Payment Services Host
ULX_PAYMENT_PROCESSOR_HOST=# A Payment Processor Service Host (processes payments)
ULX_OUTBOUND_PAYMENTS_SERVICE_HOST=# Payment Services Host
ULX_DATASTORE_LOOKUP_SERVICE_HOST=

# Price per query (microgons). This is on top of Datastore pricing, used for cloud hosting.
Expand All @@ -28,8 +28,6 @@ ULX_ENABLE_GLOBAL_CONFIG=true

## Localchain Configuration

# Alternative configuration to a machine-local localchain
ARGON_PAYMENT_ADDRESS=
# Path to the localchain
ARGON_LOCALCHAIN_PATH=
# Default Argon mainchain host TODO: fill in once mainchain is up#
Expand Down
2 changes: 1 addition & 1 deletion datastore/core/endpoints/ChannelHold.register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default new ValidatingApiHandler('ChannelHold.register', ChannelHoldApisS
): Promise<IChannelHoldApiTypes['ChannelHold.register']['result']> {
const manifest = await context.datastoreRegistry.get(request.datastoreId, null, false);
if (!manifest) throw new Error(`Unknown datastore requested ${request.datastoreId}`);
await context.micropaymentChannelSpendTracker.importChannelHold(request, manifest);
await context.argonPaymentProcessor.importChannelHold(request, manifest);
return { accepted: true };
},
});
10 changes: 5 additions & 5 deletions datastore/core/endpoints/Datastore.queryStorageEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@ulixee/platform-specification/datastore/DatastoreApis';
import DatastoreApiHandler from '../lib/DatastoreApiHandler';
import { validateAuthentication } from '../lib/datastoreUtils';
import PaymentsQueryHandler from '../lib/PaymentsProcessor';
import PaymentsProcessor from '../lib/PaymentsProcessor';

export default new DatastoreApiHandler('Datastore.queryStorageEngine', {
async handler(request, context) {
Expand All @@ -32,11 +32,11 @@ export default new DatastoreApiHandler('Datastore.queryStorageEngine', {
await validateAuthentication(datastore, payment, authentication);

const sqlParser = new SqlParser(request.sql);
const paymentHandler = new PaymentsQueryHandler(payment, id, datastore, context);
const paymentsProcessor = new PaymentsProcessor(payment, id, datastore, context);
const tableCalls = sqlParser
.extractTableCalls()
.filter(x => !request.virtualEntitiesByName?.[x]);
await paymentHandler.debit(queryId, manifestWithEntrypoint, tableCalls);
await paymentsProcessor.debit(queryId, manifestWithEntrypoint, tableCalls);

const finalResult: IDatastoreQueryResult = {
outputs: null,
Expand Down Expand Up @@ -73,9 +73,9 @@ export default new DatastoreApiHandler('Datastore.queryStorageEngine', {
basePrice += price;
}

paymentHandler.trackCallResult('query', basePrice, upstreamMeta);
paymentsProcessor.trackCallResult('query', basePrice, upstreamMeta);
const bytes = PricingManager.getOfficialBytes(finalResult.outputs);
finalResult.metadata.microgons = await paymentHandler.finalize(bytes);
finalResult.metadata.microgons = await paymentsProcessor.finalize(bytes);
finalResult.metadata.bytes = bytes;
} catch (error) {
finalResult.runError = error;
Expand Down
32 changes: 18 additions & 14 deletions datastore/core/endpoints/HostedServicesEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import ConnectionToClient from '@ulixee/net/lib/ConnectionToClient';
import { IDomainLookupApis, IPaymentServiceApis } from '@ulixee/platform-specification/datastore';
import { DomainLookupApiSchema } from '@ulixee/platform-specification/datastore/DomainLookupApis';
import { PaymentServiceApisSchema } from '@ulixee/platform-specification/datastore/PaymentServiceApis';
import {
ArgonPaymentProcessorApiSchema,
IArgonPaymentProcessorApis,
} from '@ulixee/platform-specification/services/ArgonPaymentProcessorApis';
import {
DatastoreRegistryApiSchemas,
IDatastoreRegistryApis,
} from '@ulixee/platform-specification/services/DatastoreRegistryApis';
import {
MicropaymentChannelApiSchemas,
IMicropaymentChannelApis,
} from '@ulixee/platform-specification/services/MicropaymentChannelApis';
import {
IStatsTrackerApis,
StatsTrackerApiSchemas,
Expand All @@ -24,7 +24,7 @@ import { DatastoreNotFoundError } from '../lib/errors';
export type TServicesApis = IDatastoreRegistryApis<IDatastoreApiContext> &
IStatsTrackerApis<IDatastoreApiContext> &
IPaymentServiceApis<IDatastoreApiContext> &
IMicropaymentChannelApis<IDatastoreApiContext> &
IArgonPaymentProcessorApis<IDatastoreApiContext> &
IDomainLookupApis<IDatastoreApiContext>;

export type TConnectionToServicesClient = ConnectionToClient<TServicesApis, {}>;
Expand Down Expand Up @@ -88,19 +88,23 @@ export default class HostedServicesEndpoints {
const manifest = await ctx.datastoreRegistry.get(datastoreId, version);
return await ctx.statsTracker.getForDatastoreVersion(manifest);
},
'MicropaymentChannel.getPaymentInfo': async (_args, ctx) => {
return await ctx.micropaymentChannelSpendTracker.getPaymentInfo();
'ArgonPaymentProcessor.getPaymentInfo': async (_args, ctx) => {
return await ctx.argonPaymentProcessor.getPaymentInfo();
},
'MicropaymentChannel.importChannelHold': async ({ channelHold, datastoreId }, ctx) => {
'ArgonPaymentProcessor.importChannelHold': async ({ channelHold, datastoreId }, ctx) => {
const manifest = await ctx.datastoreRegistry.get(datastoreId);
return await ctx.micropaymentChannelSpendTracker.importChannelHold({ channelHold, datastoreId }, manifest);
return await ctx.argonPaymentProcessor.importChannelHold(
{ channelHold, datastoreId },
manifest,
);
},
'MicropaymentChannel.debitPayment': async (data, ctx) => {
return await ctx.micropaymentChannelSpendTracker.debit(data);
'ArgonPaymentProcessor.debit': async (data, ctx) => {
return await ctx.argonPaymentProcessor.debit(data);
},
'MicropaymentChannel.finalizePayment': async (data, ctx) => {
return await ctx.micropaymentChannelSpendTracker.finalize(data);
'ArgonPaymentProcessor.finalize': async (data, ctx) => {
return await ctx.argonPaymentProcessor.finalize(data);
},
// upstream payments
'PaymentService.authenticate': async (_args, _ctx) => {
throw new Error('Not implemented');
},
Expand All @@ -120,7 +124,7 @@ export default class HostedServicesEndpoints {
DatastoreRegistryApiSchemas[api] ??
StatsTrackerApiSchemas[api] ??
PaymentServiceApisSchema[api] ??
MicropaymentChannelApiSchemas[api] ??
ArgonPaymentProcessorApiSchema[api] ??
DomainLookupApiSchema[api];
if (!validationSchema) throw new Error(`invalid api ${api}`);
this.handlersByCommand[api] = validateThenRun.bind(
Expand Down
4 changes: 2 additions & 2 deletions datastore/core/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default {
datastoresTmpDir: env.ULX_DATASTORE_TMP_DIR ?? Path.join(Os.tmpdir(), '.ulixee', 'datastore'),
queryHeroSessionsDir: env.ULX_QUERY_HERO_SESSIONS_DIR,
replayRegistryHost: env.ULX_REPLAY_REGISTRY_HOST,
micropaymentChannelSpendTrackingHost: env.ULX_MICROPAYMENT_CHANNEL_SPEND_TRACKING_HOST,
paymentServiceHost: env.ULX_PAYMENT_SERVICE_HOST,
argonPaymentProcessorHost: env.ULX_PAYMENT_PROCESSOR_HOST,
outboundPaymentsServiceHost: env.ULX_OUTBOUND_PAYMENTS_SERVICE_HOST,
datastoreLookupHost: env.ULX_DATASTORE_LOOKUP_SERVICE_HOST,
enableSqliteWalMode: env.ULX_ENABLE_SQLITE_WAL,
// list of identities who can upload to this Cloud [@ulixee/platform-utils/lib/Identity.bech32]
Expand Down
40 changes: 19 additions & 21 deletions datastore/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { MainchainClient } from '@argonprotocol/localchain';
import { existsAsync } from '@ulixee/commons/lib/fileUtils';
import Logger from '@ulixee/commons/lib/Logger';
import { filterUndefined } from '@ulixee/commons/lib/objectUtils';
import Resolvable from '@ulixee/commons/lib/Resolvable';
import TypedEventEmitter from '@ulixee/commons/lib/TypedEventEmitter';
import { ConnectionToDatastoreCore } from '@ulixee/datastore';
import IArgonPaymentProcessor from '@ulixee/datastore-core/interfaces/IArgonPaymentProcessor';
import ArgonPaymentProcessor from '@ulixee/datastore-core/lib/ArgonPaymentProcessor';
import IDatastoreHostLookup from '@ulixee/datastore/interfaces/IDatastoreHostLookup';
import type IExtractorPluginCore from '@ulixee/datastore/interfaces/IExtractorPluginCore';
import IPaymentService from '@ulixee/datastore/interfaces/IPaymentService';
Expand All @@ -12,21 +15,19 @@ import DatastoreLookup from '@ulixee/datastore/lib/DatastoreLookup';
import EmbeddedPaymentService from '@ulixee/datastore/payments/EmbeddedPaymentService';
import LocalchainWithSync from '@ulixee/datastore/payments/LocalchainWithSync';
import RemoteReserver from '@ulixee/datastore/payments/RemoteReserver';
import { MainchainClient } from '@argonprotocol/localchain';
import { ConnectionToCore } from '@ulixee/net';
import ITransport from '@ulixee/net/interfaces/ITransport';
import ApiRegistry from '@ulixee/net/lib/ApiRegistry';
import TransportBridge from '@ulixee/net/lib/TransportBridge';
import { IDatastoreApiTypes } from '@ulixee/platform-specification/datastore';
import { IServicesSetupApiTypes } from '@ulixee/platform-specification/services/SetupApis';
import { IDatastorePaymentRecipient } from '@ulixee/platform-specification/types/IDatastoreManifest';
import Ed25519 from '@ulixee/platform-utils/lib/Ed25519';
import Identity from '@ulixee/platform-utils/lib/Identity';
import { promises as Fs } from 'fs';
import { IncomingMessage, ServerResponse } from 'http';
import * as Path from 'path';
import MicropaymentChannelSpendTracker from '@ulixee/datastore-core/lib/MicropaymentChannelSpendTracker';
import IMicropaymentChannelSpendTracker from '@ulixee/datastore-core/interfaces/IMicropaymentChannelSpendTracker';
import { IDatastorePaymentRecipient } from '@ulixee/platform-specification/types/IDatastoreManifest';
import ChannelHoldRegister from './endpoints/ChannelHold.register';
import DatastoreAdmin from './endpoints/Datastore.admin';
import DatastoreCreateStorageEngine from './endpoints/Datastore.createStorageEngine';
import DatastoreCreditsBalance from './endpoints/Datastore.creditsBalance';
Expand All @@ -42,20 +43,19 @@ import DatastoreUpload from './endpoints/Datastore.upload';
import DatastoreVersions from './endpoints/Datastore.versions';
import DatastoresList from './endpoints/Datastores.list';
import DocpageRoutes, { datastorePathRegex } from './endpoints/DocpageRoutes';
import ChannelHoldRegister from './endpoints/ChannelHold.register';
import HostedServicesEndpoints, {
TConnectionToServicesClient,
} from './endpoints/HostedServicesEndpoints';
import Env from './env';
import IDatastoreApiContext from './interfaces/IDatastoreApiContext';
import IDatastoreConnectionToClient from './interfaces/IDatastoreConnectionToClient';
import IDatastoreCoreConfigureOptions from './interfaces/IDatastoreCoreConfigureOptions';
import ArgonPaymentProcessorClient from './lib/ArgonPaymentProcessorClient';
import DatastoreHostLookupClient from './lib/DatastoreHostLookupClient';
import DatastoreRegistry, { IDatastoreManifestWithRuntime } from './lib/DatastoreRegistry';
import { IDatastoreSourceDetails } from './lib/DatastoreRegistryDiskStore';
import DatastoreVm from './lib/DatastoreVm';
import { MissingRequiredSettingError } from './lib/errors';
import MicropaymentChannelSpendTrackerClient from './lib/MicropaymentChannelSpendTrackerClient';
import StatsTracker from './lib/StatsTracker';
import StorageEngineRegistry from './lib/StorageEngineRegistry';
import { translateStats } from './lib/translateDatastoreMetadata';
Expand Down Expand Up @@ -113,7 +113,7 @@ export default class DatastoreCore extends TypedEventEmitter<{
public datastoreRegistry: DatastoreRegistry;
public statsTracker: StatsTracker;
public storageEngineRegistry: StorageEngineRegistry;
public micropaymentChannelSpendTracker: IMicropaymentChannelSpendTracker;
public argonPaymentProcessor: IArgonPaymentProcessor;
public localchain?: LocalchainWithSync;
public upstreamDatastorePaymentService?: IPaymentService;
public datastoreHostLookup?: IDatastoreHostLookup;
Expand Down Expand Up @@ -144,8 +144,8 @@ export default class DatastoreCore extends TypedEventEmitter<{
statsTrackerHost: Env.statsTrackerHost,
queryHeroSessionsDir: Env.queryHeroSessionsDir,
replayRegistryHost: Env.replayRegistryHost,
micropaymentChannelSpendTrackingHost: Env.micropaymentChannelSpendTrackingHost,
paymentServiceHost: Env.paymentServiceHost,
argonPaymentProcessorHost: Env.argonPaymentProcessorHost,
outboundPaymentsServiceHost: Env.outboundPaymentsServiceHost,
datastoreLookupHost: Env.datastoreLookupHost,
localchainConfig: Env.localchainConfig,
...(options ?? {}),
Expand Down Expand Up @@ -253,14 +253,14 @@ export default class DatastoreCore extends TypedEventEmitter<{
if (this.options.replayRegistryHost === 'self')
this.options.replayRegistryHost = servicesHost;

if (this.options.paymentServiceHost === 'self')
this.options.paymentServiceHost = servicesHost;
if (this.options.outboundPaymentsServiceHost === 'self')
this.options.outboundPaymentsServiceHost = servicesHost;

if (this.options.datastoreLookupHost === 'self')
this.options.datastoreLookupHost = servicesHost;

if (this.options.micropaymentChannelSpendTrackingHost === 'self')
this.options.micropaymentChannelSpendTrackingHost = servicesHost;
if (this.options.argonPaymentProcessorHost === 'self')
this.options.argonPaymentProcessorHost = servicesHost;

this.options.statsTrackerHost ??= servicesHost;
this.options.datastoreRegistryHost ??= servicesHost;
Expand Down Expand Up @@ -315,15 +315,15 @@ export default class DatastoreCore extends TypedEventEmitter<{
this.datastoreApiClients,
);

this.micropaymentChannelSpendTracker = new MicropaymentChannelSpendTracker(
this.argonPaymentProcessor = new ArgonPaymentProcessor(
this.options.datastoresDir,
this.localchain,
);

this.paymentInfo.resolve(await this.localchain.paymentInfo);
} else {
const paymentServiceConnection = createConnectionToServiceHost(
this.options.paymentServiceHost,
this.options.outboundPaymentsServiceHost,
);
const argonReserver = paymentServiceConnection
? new RemoteReserver(paymentServiceConnection)
Expand All @@ -332,13 +332,11 @@ export default class DatastoreCore extends TypedEventEmitter<{
this.upstreamDatastorePaymentService = new EmbeddedPaymentService(argonReserver);

const channelHoldConnection = createConnectionToServiceHost(
this.options.micropaymentChannelSpendTrackingHost,
this.options.argonPaymentProcessorHost,
);
if (channelHoldConnection) {
this.micropaymentChannelSpendTracker = new MicropaymentChannelSpendTrackerClient(
channelHoldConnection,
);
this.paymentInfo.resolve(await this.micropaymentChannelSpendTracker.getPaymentInfo());
this.argonPaymentProcessor = new ArgonPaymentProcessorClient(channelHoldConnection);
this.paymentInfo.resolve(await this.argonPaymentProcessor.getPaymentInfo());
}
}
if (!this.paymentInfo.isResolved) {
Expand Down Expand Up @@ -526,7 +524,7 @@ export default class DatastoreCore extends TypedEventEmitter<{
vm: this.vm,
datastoreApiClients: this.datastoreApiClients,
statsTracker: this.statsTracker,
micropaymentChannelSpendTracker: this.micropaymentChannelSpendTracker,
argonPaymentProcessor: this.argonPaymentProcessor,
upstreamDatastorePaymentService: this.upstreamDatastorePaymentService,
datastoreLookup: this.datastoreHostLookup,
};
Expand Down
Loading

0 comments on commit 3fbfaae

Please sign in to comment.