Skip to content

Commit

Permalink
feat(pol): add support for matic/pol crypto fund PE-6722
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Sep 13, 2024
1 parent 8dcdae7 commit c6ff0b3
Show file tree
Hide file tree
Showing 13 changed files with 424 additions and 265 deletions.
6 changes: 3 additions & 3 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import { Command, program } from 'commander';

import { version } from '../version.js';
import {
balance,
cryptoFund,
getBalance,
topUp,
uploadFile,
uploadFolder,
} from './commands.js';
} from './commands/index.js';
import {
globalOptions,
optionMap,
Expand All @@ -50,7 +50,7 @@ applyOptions(
program.command('balance').description('Get balance of a Turbo address'),
[optionMap.address, ...walletOptions],
).action(async (_commandOptions, command: Command) => {
await runCommand(command, getBalance);
await runCommand(command, balance);
});

applyOptions(
Expand Down
260 changes: 0 additions & 260 deletions src/cli/commands.ts

This file was deleted.

53 changes: 53 additions & 0 deletions src/cli/commands/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { TurboFactory } from '../../node/factory.js';
import { AddressOptions } from '../types.js';
import { addressOrPrivateKeyFromOptions, configFromOptions } from '../utils.js';

export async function balance(options: AddressOptions) {
const config = configFromOptions(options);

const { address, privateKey } = await addressOrPrivateKeyFromOptions(options);

if (address !== undefined) {
const turbo = TurboFactory.unauthenticated(config);
const { winc } = await turbo.getBalance(address);

console.log(
`Turbo Balance for Native Address "${address}"\nCredits: ${
+winc / 1_000_000_000_000
}`,
);
return;
}

if (privateKey === undefined) {
throw new Error('Must provide an (--address) or use a valid wallet');
}

const turbo = TurboFactory.authenticated({
...config,
privateKey,
});

const { winc } = await turbo.getBalance();
console.log(
`Turbo Balance for Wallet Address "${await turbo.signer.getNativeAddress()}"\nCredits: ${
+winc / 1_000_000_000_000
}`,
);
}
Loading

0 comments on commit c6ff0b3

Please sign in to comment.