Skip to content

Commit

Permalink
Merge pull request #2 from atomicals-community/fix/remove-unnecessary…
Browse files Browse the repository at this point in the history
…-verbose

Remove unnecessary verbose parameters
  • Loading branch information
wizz-wallet-dev authored Jun 13, 2024
2 parents 5610e01 + 87e3359 commit ab13bdb
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 54 deletions.
10 changes: 5 additions & 5 deletions lib/api/electrum-api-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ElectrumApiMock implements ElectrumApiInterface {
}

async dump() {

}

async resetConnection() {
Expand All @@ -34,7 +34,7 @@ export class ElectrumApiMock implements ElectrumApiInterface {
return null;
}



setSendTransaction(cb: Function) {
return this.sendTransactionCallback = cb;
Expand Down Expand Up @@ -73,7 +73,7 @@ export class ElectrumApiMock implements ElectrumApiInterface {
return this.getTxCallback = cb;
}

async getTx(txid: string, verbose = false): Promise<any> {
async getTx(txid: string): Promise<any> {
if (!this.getTxCallback) {
throw "getTxCallback undefined";
}
Expand Down Expand Up @@ -118,7 +118,7 @@ export class ElectrumApiMock implements ElectrumApiInterface {
public async atomicalsGetFtInfo(atomicalAliasOrId: string | number): Promise<any> {
return "atomicalsGetFtInfo"
}

public async atomicalsGetLocation(atomicalAliasOrId: string | number): Promise<any> {
return "atomicalsGetLocation"
}
Expand Down Expand Up @@ -170,7 +170,7 @@ export class ElectrumApiMock implements ElectrumApiInterface {
public async atomicalsGetByContainerItemValidated(container: string, item: string, bitworkc: string, bitworkr: string, main: string, mainHash: string, proof: any, checkWithoutSealed: boolean): Promise<any> {
return "atomicalsGetByContainerItemValidated"
}

public async atomicalsFindTickers(tickerPrefix: string | null, asc?: boolean): Promise<any> {
return "atomicalsFindTickers"
}
Expand Down
8 changes: 4 additions & 4 deletions lib/api/electrum-api.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ElectrumApiInterface {
getUnspentAddress: (address: string) => Promise<IUnspentResponse>;
getUnspentScripthash: (address: string) => Promise<IUnspentResponse>;
waitUntilUTXO: (address: string, satoshis: number, sleepTimeSec: number, exactSatoshiAmount?: boolean) => Promise<UTXO>;
getTx: (txid: string, verbose?: boolean) => Promise<any>;
getTx: (txid: string) => Promise<any>;
serverVersion: () => Promise<any>;
broadcast: (rawtx: string, force?: boolean) => Promise<any>;
history: (scripthash: string) => Promise<any>;
Expand All @@ -27,7 +27,7 @@ export interface ElectrumApiInterface {
atomicalsGet: (atomicalAliasOrId: string | number) => Promise<any>;
atomicalsGetFtInfo: (atomicalAliasOrId: string | number) => Promise<any>;
atomicalsGetLocation: (atomicalAliasOrId: string | number) => Promise<any>;
atomicalsGetState: (atomicalAliasOrId: string | number, verbose: boolean) => Promise<any>;
atomicalsGetState: (atomicalAliasOrId: string | number) => Promise<any>;
atomicalsGetStateHistory: (atomicalAliasOrId: string | number) => Promise<any>;
atomicalsGetEventHistory: (atomicalAliasOrId: string | number) => Promise<any>;
atomicalsGetTxHistory: (atomicalAliasOrId: string | number) => Promise<any>;
Expand All @@ -38,12 +38,12 @@ export interface ElectrumApiInterface {
atomicalsGetByContainerItem: (container: string, item: string) => Promise<any>;
atomicalsGetByContainerItemValidated: (container: string, item: string, bitworkc: string, bitworkr: string, main: string, mainHash: string, proof: any, checkWithoutSealed: boolean) => Promise<any>;
atomicalsGetByRealm: (realm: string) => Promise<any>;
atomicalsGetRealmInfo: (realmOrSubRealm: string, verbose?: boolean) => Promise<any>;
atomicalsGetRealmInfo: (realmOrSubRealm: string) => Promise<any>;
atomicalsGetByTicker: (ticker: string) => Promise<any>;
atomicalsGetByContainer: (container: string) => Promise<any>;
atomicalsGetContainerItems: (container: string, limit: number, offset: number) => Promise<any>;
atomicalsFindTickers: (tickerPrefix: string | null, asc?: boolean) => Promise<any>;
atomicalsFindContainers: (containerPrefix: string | null, asc?: boolean) => Promise<any>;
atomicalsFindRealms: (realmPrefix: string | null, asc?: boolean) => Promise<any>;
atomicalsFindSubRealms: (parentRealmId: string, subrealmPrefix: string | null, mostRecentFirst?: boolean) => Promise<any>;
}
}
12 changes: 6 additions & 6 deletions lib/api/electrum-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ export class ElectrumApi implements ElectrumApiInterface {
url: url,
...(this.usePost ? { data: { params } } : { params: params })
};

const response = await axios(options);
return response.data.response;
} catch (error) {
console.log(`Error using endpoint ${baseUrl}:`, error);
}
}

throw new Error('All endpoints failed');
}

public sendTransaction(signedRawTx: string): Promise<any> {
return this.broadcast(signedRawTx);
}

public getTx(txId: string, verbose = false): Promise<any> {
public getTx(txId: string): Promise<any> {
return new Promise((resolve, reject) => {
this.call('blockchain.transaction.get', [txId, verbose ? 1 : 0]
this.call('blockchain.transaction.get', [txId]
).then((result: any) => {
resolve({success: true, tx: result});
}).catch((error) => reject(error))
Expand Down Expand Up @@ -210,8 +210,8 @@ export class ElectrumApi implements ElectrumApiInterface {
return this.call('blockchain.atomicals.get_state_history', [atomicalAliasOrId]);
}

public atomicalsGetState(atomicalAliasOrId: string | number, verbose: boolean): Promise<any> {
return this.call('blockchain.atomicals.get_state', [atomicalAliasOrId, verbose ? 1 : 0]);
public atomicalsGetState(atomicalAliasOrId: string | number): Promise<any> {
return this.call('blockchain.atomicals.get_state', [atomicalAliasOrId]);
}

public atomicalsGetEventHistory(atomicalAliasOrId: string | number): Promise<any> {
Expand Down
3 changes: 1 addition & 2 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,9 @@ program.command('tx')
.action(async (txid, options) => {
try {
await validateWalletStorage();
const verbose = options.verbose ? true : false;
const config: ConfigurationInterface = validateCliInputs();
const atomicals = new Atomicals(ElectrumApi.createClient(process.env.ELECTRUMX_PROXY_BASE_URL || ''));
const result = await atomicals.getTx(txid, verbose);
const result = await atomicals.getTx(txid);
console.log(JSON.stringify(result, null, 2));
} catch (error) {
console.log(error);
Expand Down
3 changes: 1 addition & 2 deletions lib/commands/get-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class GetCommand implements CommandInterface {
constructor(private electrumApi: ElectrumApiInterface,
private atomicalAliasOrId: string,
private fetchType: AtomicalsGetFetchType = AtomicalsGetFetchType.GET,
private verbose?: boolean
) {
}

Expand All @@ -17,7 +16,7 @@ export class GetCommand implements CommandInterface {
} else if (this.fetchType === AtomicalsGetFetchType.LOCATION) {
response = await this.electrumApi.atomicalsGetLocation(this.atomicalAliasOrId);
} else if (this.fetchType === AtomicalsGetFetchType.STATE) {
response = await this.electrumApi.atomicalsGetState(this.atomicalAliasOrId, this.verbose || false);
response = await this.electrumApi.atomicalsGetState(this.atomicalAliasOrId);
} else if (this.fetchType === AtomicalsGetFetchType.STATE_HISTORY) {
response = await this.electrumApi.atomicalsGetStateHistory(this.atomicalAliasOrId);
} else if (this.fetchType === AtomicalsGetFetchType.EVENT_HISTORY) {
Expand Down
5 changes: 2 additions & 3 deletions lib/commands/tx-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ export class TxCommand implements CommandInterface {
constructor(
private electrumApi: ElectrumApiInterface,
private txid: string,
private verbose: boolean
) {
}

async run(): Promise<any> {
return this.electrumApi.getTx(this.txid, this.verbose);
return this.electrumApi.getTx(this.txid);
}
}
}
54 changes: 27 additions & 27 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,30 +457,30 @@ export class Atomicals implements APIInterface {
requestTicker: string,
mintAmount: number,
maxMints: number,
mintHeight: number,
mintBitworkVector: string,
mintBitworkCommitIncrement: number,
mintBitworkRevealIncrement: number | null,
mintHeight: number,
mintBitworkVector: string,
mintBitworkCommitIncrement: number,
mintBitworkRevealIncrement: number | null,
mintBitworkCommitIncrementStart: number | null,
mintBitworkRevealIncrementStart: number | null,
mintBitworkRevealIncrementStart: number | null,
maxGlobalMints: number | null,
WIF: string,
noImage?: boolean,
): Promise<CommandResultInterface> {
try {
await this.electrumApi.open();
const command: CommandInterface = new InitInteractiveInfiniteDftCommand(
this.electrumApi,
options,
this.electrumApi,
options,
file,
address,
requestTicker,
mintAmount,
maxMints,
mintHeight,
mintBitworkVector,
mintAmount,
maxMints,
mintHeight,
mintBitworkVector,
mintBitworkCommitIncrement,
mintBitworkRevealIncrement,
mintBitworkRevealIncrement,
mintBitworkCommitIncrementStart,
mintBitworkRevealIncrementStart,
maxGlobalMints,
Expand All @@ -505,25 +505,25 @@ export class Atomicals implements APIInterface {
requestTicker: string,
mintAmount: number,
maxMints: number,
mintHeight: number,
mintBitworkCommit: string,
mintBitworkReveal: string | null,
mintHeight: number,
mintBitworkCommit: string,
mintBitworkReveal: string | null,
WIF: string,
noImage?: boolean,
): Promise<CommandResultInterface> {
try {
await this.electrumApi.open();
const command: CommandInterface = new InitInteractiveFixedDftCommand(
this.electrumApi,
options,
this.electrumApi,
options,
file,
address,
requestTicker,
mintAmount,
maxMints,
mintHeight,
mintBitworkCommit,
mintBitworkReveal,
mintAmount,
maxMints,
mintHeight,
mintBitworkCommit,
mintBitworkReveal,
WIF,
noImage);
return await command.run();
Expand Down Expand Up @@ -634,7 +634,7 @@ export class Atomicals implements APIInterface {
this.electrumApi.close();
}
}

async emitInteractive(options: BaseRequestOptions, atomicalId: string, files: string[], funding: IWalletRecord, atomicalOwner: IWalletRecord): Promise<CommandResultInterface> {
try {
await this.electrumApi.open();
Expand Down Expand Up @@ -962,10 +962,10 @@ export class Atomicals implements APIInterface {
}
}

async getAtomicalState(atomicalAliasOrId: string, verbose: boolean = false, keepElectrumAlive = false): Promise<CommandResultInterface> {
async getAtomicalState(atomicalAliasOrId: string, keepElectrumAlive = false): Promise<CommandResultInterface> {
try {
await this.electrumApi.open();
const command: CommandInterface = new GetCommand(this.electrumApi, atomicalAliasOrId, AtomicalsGetFetchType.STATE, verbose);
const command: CommandInterface = new GetCommand(this.electrumApi, atomicalAliasOrId, AtomicalsGetFetchType.STATE);
return await command.run();
} catch (error: any) {
return {
Expand Down Expand Up @@ -1384,10 +1384,10 @@ export class Atomicals implements APIInterface {
}
}

async getTx(txid: string, verbose: boolean): Promise<CommandResultInterface> {
async getTx(txid: string): Promise<CommandResultInterface> {
try {
await this.electrumApi.open();
const command: CommandInterface = new TxCommand(this.electrumApi, txid, verbose);
const command: CommandInterface = new TxCommand(this.electrumApi, txid);
return await command.run();
} catch (error: any) {
return {
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/api.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface APIInterface {
getAtomical(atomicalId: string, keepElectrumAlive: boolean): Promise<CommandResultInterface>;
getAtomicalLocation(atomicalId: string, keepElectrumAlive: boolean): Promise<CommandResultInterface>;
getAtomicalHistory(atomicalId: string, keepElectrumAlive: boolean): Promise<CommandResultInterface>;
getAtomicalState(atomicalId: string, verbose: boolean, keepElectrumAlive: boolean): Promise<CommandResultInterface>;
getAtomicalState(atomicalId: string, keepElectrumAlive: boolean): Promise<CommandResultInterface>;
getAtomicalStateHistory(atomicalId: string, keepElectrumAlive: boolean): Promise<CommandResultInterface>;
getAtomicalEventHistory(atomicalId: string, keepElectrumAlive: boolean): Promise<CommandResultInterface>;
searchTickers(prefix: string, keepElectrumAlive: boolean): Promise<CommandResultInterface>;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atomicals-js",
"version": "0.1.79",
"version": "0.1.80",
"description": "Atomicals Javascript Library and CLI",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions test/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var expect = require('chai').expect;
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var index = require('../dist/index.js');

require('dotenv').config();

describe('e2e', () => {
it('get latest state', async () => {
const atomicals = new index.Atomicals(index.ElectrumApi.createClient(process.env.ELECTRUMX_PROXY_BASE_URL || ''));
const state = await atomicals.getAtomicalState('1', true);
const state = await atomicals.getAtomicalState('1');
console.log('state', state);


});
});
});

0 comments on commit ab13bdb

Please sign in to comment.