-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cd5072
commit 33f117d
Showing
8 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Command } from "commander" | ||
import { EntropyTemplate } from "./main" | ||
import { cliWrite, accountOption, endpointOption, loadEntropy, passwordOption } from "../common/utils-cli"; | ||
|
||
|
||
const command = { | ||
name: 'transfer' | ||
alias: [''] | ||
description: 'Transfer funds between two Entropy accounts.' | ||
// should be order | ||
args: [ | ||
{name: 'destination', description: 'Account address funds will be sent to'}, | ||
{name: 'ammount', description: 'Amount of funds to be moved'}, | ||
], | ||
optionFlags: [ | ||
endpointOption | ||
], | ||
|
||
} | ||
|
||
|
||
export function entropyTeplateCommand () { | ||
const transferCommand = new Command('tranfer') | ||
transferCommand | ||
.description(command.description) // TODO: name the output | ||
.argument('destination', 'Account address funds will be sent to') | ||
.argument('amount', 'Amount of funds to be moved') | ||
.addOption(passwordOption('Password for the source account (if required)')) | ||
.addOption(endpointOption()) | ||
.addOption(accountOption()) | ||
.action(async (destination, amount, opts) => { | ||
// load entropy | ||
const entropy = await loadEntropy(opts.account, opts.endpoint) | ||
// create service | ||
const transferService = new EntropyTransfer(entropy, opts.endpoint) | ||
// use sevice | ||
await transferService.transfer(destination, amount) | ||
// cliWrite(??) // TODO: write the output | ||
process.exit(0) | ||
}) | ||
return transferCommand | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const PROMPT_CONTENT = { | ||
amount: { | ||
name: 'amount', | ||
message: 'Input amount to transfer:', | ||
default: '1', | ||
invalidError: 'Please enter a value greater than 0', | ||
}, | ||
recipientAddress: { | ||
name: 'recipientAddress', | ||
message: `Input recipient's address:`, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import inquirer from "inquirer" | ||
import { print } from "../common/utils" | ||
import { EntropyTransfer } from "./main" | ||
import { transferInputQuestions } from "./utils" | ||
import { setupProgress } from "src/common/progress" | ||
|
||
export async function entropyTransfer (entropy, endpoint) { | ||
const progressTracker = setupProgress('Transferring Funds') | ||
const transferService = new EntropyTransfer(entropy, endpoint) | ||
const { amount, recipientAddress } = await inquirer.prompt(transferInputQuestions) | ||
await transferService.transfer(recipientAddress, amount, progressTracker) | ||
print('') | ||
print(`Transaction successful: Sent ${amount} to ${recipientAddress}`) | ||
print('') | ||
print('Press enter to return to main menu') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { EntropyBase } from "../common/entropy-base"; | ||
|
||
/* | ||
This provides core functions that should be unit tested | ||
consumed by both ./command.ts and ./interaction.ts | ||
should follow a pattern of take in arguments return result with little side effects | ||
in between NO PRINTING! | ||
atempt strict typeing | ||
*/ | ||
|
||
|
||
// this is for logger context incase something fails and a user can provide a report | ||
const FLOW_CONTEXT = 'ENTROPY_TEMPLATE' | ||
|
||
export class EntropyTemplate extends EntropyBase { | ||
constructor (entropy: Entropy, endpoint: string) { | ||
super({ entropy, endpoint, flowContext: FLOW_CONTEXT }) | ||
} | ||
|
||
async mainExcutableFunction () { | ||
// write code requireing the use of entropy! | ||
} | ||
|
||
static async classMethod () { | ||
// write stateless one-offs | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// @ts-ignore | ||
/* | ||
RECORD TYPES HERE | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { TRANSFER_CONTENT } from "./constants"; | ||
|
||
function validateAmount (amount: string | number) { | ||
if (isNaN(amount as number) || parseInt(amount as string) <= 0) { | ||
return TRANSFER_CONTENT.amount.invalidError | ||
} | ||
return true | ||
} | ||
|
||
const amountQuestion = { | ||
type: 'input', | ||
name: TRANSFER_CONTENT.amount.name, | ||
message: TRANSFER_CONTENT.amount.message, | ||
default: TRANSFER_CONTENT.amount.default, | ||
validate: validateAmount | ||
} | ||
|
||
const recipientAddressQuestion = { | ||
type: 'input', | ||
name: TRANSFER_CONTENT.recipientAddress.name, | ||
message: TRANSFER_CONTENT.recipientAddress.message, | ||
} | ||
|
||
export const transferInputQuestions = [ | ||
amountQuestion, | ||
recipientAddressQuestion | ||
] |