Skip to content

Commit

Permalink
chore: adding ability to override registry
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Oct 24, 2023
1 parent ea2a3da commit f8f9ef9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/clients/SubtopiaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class SubtopiaClient {
appAddress: string;
appSpec: ApplicationSpec;
timeout: number;
registryID: number;

protected constructor({
algodClient,
Expand All @@ -93,6 +94,7 @@ export class SubtopiaClient {
coin,
version,
timeout,
registryID,
}: {
algodClient: AlgodClient;
productName: string;
Expand All @@ -106,6 +108,7 @@ export class SubtopiaClient {
coin: AssetMetadata;
version: string;
timeout: number;
registryID: number;
}) {
this.algodClient = algodClient;
this.productName = productName;
Expand All @@ -119,6 +122,7 @@ export class SubtopiaClient {
this.coin = coin;
this.version = version;
this.timeout = timeout;
this.registryID = registryID;
}

/**
Expand All @@ -129,6 +133,7 @@ export class SubtopiaClient {
* @param {number} productID - The ID of the product.
* @param {TransactionSignerAccount} creator - The account that will sign the transactions.
* @param {number} timeout - The timeout for the transactions (default is DEFAULT_TXN_SIGN_TIMEOUT_SECONDS).
* @param {number} registryID - The ID of the registry (default is TESTNET_SUBTOPIA_REGISTRY_ID).
*
* @returns {Promise<SubtopiaClient>} A promise that resolves to a SubtopiaClient instance.
*
Expand All @@ -147,7 +152,8 @@ export class SubtopiaClient {
algodClient: AlgodClient,
productID: number,
creator: TransactionSignerAccount,
timeout: number = DEFAULT_TXN_SIGN_TIMEOUT_SECONDS
timeout: number = DEFAULT_TXN_SIGN_TIMEOUT_SECONDS,
registryID: number = TESTNET_SUBTOPIA_REGISTRY_ID
): Promise<SubtopiaClient> {
const productGlobalState = await getAppGlobalState(
productID,
Expand Down Expand Up @@ -231,6 +237,7 @@ export class SubtopiaClient {
coin,
version,
timeout,
registryID,
});
}

Expand Down Expand Up @@ -690,7 +697,7 @@ export class SubtopiaClient {
const platformFeeAmount = await this.getSubscriptionPlatformFee();
const state = await this.getAppState();
const managerLockerID = await SubtopiaRegistryClient.getLocker({
registryID: TESTNET_SUBTOPIA_REGISTRY_ID,
registryID: this.registryID,
algodClient: this.algodClient,
ownerAddress: state.manager,
lockerType: LockerType.CREATOR,
Expand Down
17 changes: 10 additions & 7 deletions src/clients/SubtopiaRegistryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,24 @@ export class SubtopiaRegistryClient {
algodClient: AlgodClient,
creator: TransactionSignerAccount,
chainType: ChainType,
timeout: number = DEFAULT_TXN_SIGN_TIMEOUT_SECONDS
timeout: number = DEFAULT_TXN_SIGN_TIMEOUT_SECONDS,
registryID?: number
): Promise<SubtopiaRegistryClient> {
const registryID = SUBTOPIA_REGISTRY_ID(chainType);
const registryAddress = getApplicationAddress(registryID);
const registrySpec = await getAppById(registryID, algodClient);
const registryId = registryID
? registryID
: SUBTOPIA_REGISTRY_ID(chainType);
const registryAddress = getApplicationAddress(registryId);
const registrySpec = await getAppById(registryId, algodClient);

const registryGlobalState = await getAppGlobalState(
registryID,
registryId,
algodClient
);
const oracleID = registryGlobalState.oracle_id.value as number;

const versionAtc = new AtomicTransactionComposer();
versionAtc.addMethodCall({
appID: registryID,
appID: registryId,
method: new ABIMethod({
name: "get_version",
args: [],
Expand Down Expand Up @@ -173,7 +176,7 @@ export class SubtopiaRegistryClient {
return new SubtopiaRegistryClient({
algodClient: algodClient,
creator: creator,
appID: registryID,
appID: registryId,
appAddress: registryAddress,
appSpec: {
approval: registrySpec.params.approvalProgram,
Expand Down

0 comments on commit f8f9ef9

Please sign in to comment.