-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QA file-restructure #247
QA file-restructure #247
Changes from all commits
148b6f8
657e6fa
ca9e31f
c68d66d
c0f24a5
8730871
96371f8
ae8c88c
a415db0
fb4691b
f686ce3
6eccbba
27a994e
9e6373d
ea23881
228ec95
215f26f
9d4ed23
d9d69a5
ebaf352
6aa5c15
8724a7f
f117c1b
4f1c0ca
3a0f362
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ export function entropyAccountCommand () { | |
.addCommand(entropyAccountImport()) | ||
.addCommand(entropyAccountList()) | ||
.addCommand(entropyAccountRegister()) | ||
// .addCommand(entropyAccountAlias()) | ||
// IDEA: support aliases for remote accounts (those we don't have seeds for) | ||
// this would make transfers safer/ easier from CLI | ||
} | ||
|
||
function entropyAccountCreate () { | ||
|
@@ -34,7 +37,8 @@ function entropyAccountCreate () { | |
|
||
cliWrite({ | ||
name: newAccount.name, | ||
address: newAccount.address | ||
address: newAccount.address, | ||
verifyingKeys: [] | ||
}) | ||
process.exit(0) | ||
}) | ||
|
@@ -59,7 +63,8 @@ function entropyAccountImport () { | |
|
||
cliWrite({ | ||
name: newAccount.name, | ||
address: newAccount.address | ||
address: newAccount.address, | ||
verifyingKeys: [] | ||
}) | ||
process.exit(0) | ||
}) | ||
|
@@ -70,8 +75,15 @@ function entropyAccountList () { | |
.alias('ls') | ||
.description('List all accounts. Output is JSON of form [{ name, address, verifyingKeys }]') | ||
.action(async () => { | ||
const storedConfig = await config.get() | ||
const accounts = EntropyAccount.list(storedConfig) | ||
// TODO: test if it's an encrypted account, if no password provided, throw because later on there's no protection from a prompt coming up | ||
const accounts = await config.get() | ||
.then(storedConfig => EntropyAccount.list(storedConfig)) | ||
.catch((err) => { | ||
if (err.message.includes('currently no accounts')) return [] | ||
|
||
throw err | ||
}) | ||
|
||
Comment on lines
+79
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CHANGE: If I don't have any accounts yet I don't expect an error, I expect |
||
cliWrite(accounts) | ||
process.exit(0) | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { FLOW_CONTEXT } from "./constants"; | |
import { AccountCreateParams, AccountImportParams, AccountRegisterParams } from "./types"; | ||
|
||
import { EntropyBase } from "../common/entropy-base"; | ||
import { EntropyAccountConfig } from "../config/types"; | ||
import { EntropyAccountConfig, EntropyAccountConfigFormatted } from "../config/types"; | ||
|
||
export class EntropyAccount extends EntropyBase { | ||
constructor (entropy: Entropy, endpoint: string) { | ||
|
@@ -19,26 +19,28 @@ export class EntropyAccount extends EntropyBase { | |
return EntropyAccount.import({ name, seed, path }) | ||
} | ||
|
||
// WARNING: #create depends on #import => be careful modifying this function | ||
static async import ({ name, seed, path }: AccountImportParams ): Promise<EntropyAccountConfig> { | ||
// WARNING: #create currently depends on this => be careful modifying this function | ||
|
||
await wasmGlobalsReady() | ||
const keyring = new Keyring({ seed, path, debug: true }) | ||
|
||
const fullAccount = keyring.getAccount() | ||
// TODO: sdk should create account on constructor | ||
const { admin } = keyring.getAccount() | ||
const data = fixData(fullAccount) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a bug in the SDK where you are "cloning" with `JSON.parse(JSON.stringify(obj)) and it fucks up the Uint8Array, which then fucks up config, logging etc. This is a quick hack |
||
const maybeEncryptedData = data | ||
// const maybeEncryptedData = password ? passwordFlow.encrypt(data, password) : data | ||
|
||
const data = fullAccount | ||
const { admin } = keyring.getAccount() | ||
delete admin.pair | ||
|
||
return { | ||
name, | ||
address: admin.address, | ||
data | ||
data: maybeEncryptedData, | ||
} | ||
} | ||
|
||
static list ({ accounts }: { accounts: EntropyAccountConfig[] }) { | ||
static list ({ accounts }: { accounts: EntropyAccountConfig[] }): EntropyAccountConfigFormatted[] { | ||
if (!accounts.length) | ||
throw new Error( | ||
'AccountsError: There are currently no accounts available, please create or import a new account using the Manage Accounts feature' | ||
|
@@ -47,7 +49,7 @@ export class EntropyAccount extends EntropyBase { | |
return accounts.map((account: EntropyAccountConfig) => ({ | ||
name: account.name, | ||
address: account.address, | ||
verifyingKeys: account?.data?.admin?.verifyingKeys | ||
verifyingKeys: account?.data?.registration?.verifyingKeys || [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 CHECK? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AH tests say no. I don't know what the difference is between `admin + registration. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed tests |
||
})) | ||
} | ||
|
||
|
@@ -88,7 +90,7 @@ export class EntropyAccount extends EntropyBase { | |
dispatchError.asModule | ||
) | ||
const { docs, name, section } = decoded | ||
|
||
msg = `${section}.${name}: ${docs.join(' ')}` | ||
} else { | ||
// Other, CannotLookup, BadOrigin, no extra info | ||
|
@@ -105,3 +107,36 @@ export class EntropyAccount extends EntropyBase { | |
}) | ||
} | ||
} | ||
|
||
// TODO: there is a bug in SDK that is munting this data | ||
function fixData (data) { | ||
if (data.admin?.pair) { | ||
const { addressRaw, secretKey, publicKey } = data.admin.pair | ||
Object.assign(data.admin.pair, { | ||
addressRaw: objToUint8Array(addressRaw), | ||
secretKey: objToUint8Array(secretKey), | ||
publicKey: objToUint8Array(publicKey) | ||
}) | ||
} | ||
|
||
if (data.registration?.pair) { | ||
const { addressRaw, secretKey, publicKey } = data.registration.pair | ||
Object.assign(data.registration.pair, { | ||
addressRaw: objToUint8Array(addressRaw), | ||
secretKey: objToUint8Array(secretKey), | ||
publicKey: objToUint8Array(publicKey) | ||
}) | ||
} | ||
|
||
return data | ||
} | ||
|
||
function objToUint8Array (input) { | ||
if (input instanceof Uint8Array) return input | ||
|
||
const values: any = Object.entries(input) | ||
.sort((a, b) => Number(a[0]) - Number(b[0])) // sort entries by keys | ||
.map(entry => entry[1]) | ||
|
||
return new Uint8Array(values) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
import { Command } from "commander"; | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { cliWrite, endpointOption, loadEntropy } from "src/common/utils-cli"; | ||
|
||
import { EntropyBalance } from "./main"; | ||
import { endpointOption, cliWrite, loadEntropy } from "../common/utils-cli"; | ||
import { findAccountByAddressOrName } from "../common/utils"; | ||
import * as config from "../config"; | ||
|
||
export function entropyBalanceCommand () { | ||
const balanceCommand = new Command('balance') | ||
balanceCommand | ||
.description('Command to retrieive the balance of an account on the Entropy Network') | ||
.argument('address', 'Account address whose balance you want to query') | ||
.argument('account <address|name>', 'Account address whose balance you want to query') | ||
.addOption(endpointOption()) | ||
.action(async (address, opts) => { | ||
const entropy: Entropy = await loadEntropy(address, opts.endpoint) | ||
.action(async (account, opts) => { | ||
const entropy: Entropy = await loadEntropy(account, opts.endpoint) | ||
const BalanceService = new EntropyBalance(entropy, opts.endpoint) | ||
|
||
const { accounts } = await config.get() | ||
const address = findAccountByAddressOrName(accounts, account)?.address | ||
|
||
const balance = await BalanceService.getBalance(address) | ||
cliWrite(`${balance.toLocaleString('en-US')} BITS`) | ||
process.exit(0) | ||
}) | ||
|
||
return balanceCommand | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PATCH:
entropy account create
entropy account create
Have them output the same format as
entropy account ls
✔️ consistency
✔️ set up expectations that there is something interesting/ important meant to go in here