-
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
[NayNay] File Restructure: Base Class + Balance Restructure #207
Merged
+170
−116
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4b802e0
[NayNay] File Restructure: Base Class + Balance Restructure
rh0delta 5d64729
updated naming scheme for command, utils and base class
rh0delta 366072b
more naming changes
rh0delta cd1b817
changelog updated
rh0delta c0fbd87
naming is fun
rh0delta 05c82ed
updated utils to be pure functions rather than class; updated tests; …
rh0delta e8aef10
Update CHANGELOG.md
rh0delta 4db6378
Merge branch 'naynay/file-restructure' into naynay/base-plus-balance
rh0delta 953f968
Merge branch 'naynay/base-plus-balance' of https://github.com/entropy…
rh0delta f1b87f4
lint errors
rh0delta 67c33cb
added lifecycle hook to main entropy entry point to load entropy inst…
rh0delta d6d8d76
updated tui and cli to be the main source of entry for everything and…
rh0delta aefe05e
updated changelog
rh0delta 197a815
undid commented code
rh0delta 423631c
little cleanup
rh0delta ddbd6e3
removed unnecessary constants file
rh0delta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Entropy from "@entropyxyz/sdk" | ||
import { Base } from "../common/base" | ||
import { BalanceUtils } from "./utils" | ||
import { FLOW_CONTEXT } from "./constants" | ||
|
||
export class BalanceCommand extends Base { | ||
private readonly balanceService: BalanceUtils | ||
|
||
constructor (entropy: Entropy, endpoint: string) { | ||
super(entropy, endpoint, FLOW_CONTEXT) | ||
this.balanceService = new BalanceUtils(this.entropy, endpoint) | ||
} | ||
|
||
public async getBalance (address: string) { | ||
const balance = await this.balanceService.getBalance(address) | ||
|
||
this.logger.log(`Current balance of ${address}: ${balance}`, `${BalanceCommand.name}`) | ||
|
||
return `${balance.toLocaleString('en-US')} BITS` | ||
} | ||
} |
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 @@ | ||
export const FLOW_CONTEXT = 'ENTROPY-BALANCE' |
File renamed without changes.
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,44 @@ | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { Base } from "../common/base"; | ||
import { BalanceInfo } from "./types"; | ||
import { FLOW_CONTEXT } from "./constants"; | ||
|
||
const hexToBigInt = (hexString: string) => BigInt(hexString) | ||
|
||
export class BalanceUtils extends Base { | ||
constructor (entropy: Entropy, endpoint: string) { | ||
super(entropy, endpoint, FLOW_CONTEXT) | ||
} | ||
|
||
public async getBalance (address: string): Promise<number> { | ||
try { | ||
const accountInfo = (await this.entropy.substrate.query.system.account(address)) as any | ||
|
||
return parseInt(hexToBigInt(accountInfo.data.free).toString()) | ||
} catch (error) { | ||
this.logger.error(`There was an error getting balance for [acct = ${address}]`, error); | ||
throw new Error(error.message) | ||
} | ||
} | ||
|
||
public async getBalances (addresses: string[]): Promise<BalanceInfo> { | ||
const balanceInfo: BalanceInfo = {} | ||
try { | ||
await Promise.all(addresses.map(async address => { | ||
try { | ||
const balance = await this.getBalance(address) | ||
|
||
balanceInfo[address] = { balance } | ||
} catch (error) { | ||
this.logger.error(`Error retrieving balance for ${address}`, error); | ||
balanceInfo[address] = { error: error.message } | ||
} | ||
})) | ||
|
||
return balanceInfo | ||
} catch (error) { | ||
this.logger.error(`There was an error getting balances for [${addresses}]`, error); | ||
throw new Error(error.message) | ||
} | ||
} | ||
rh0delta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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 @@ | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { EntropyLogger } from "./logger"; | ||
|
||
export abstract class Base { | ||
protected logger: EntropyLogger | ||
protected entropy: Entropy | ||
|
||
constructor (entropy: Entropy, endpoint: string, flowContext: string) { | ||
this.logger = new EntropyLogger(flowContext, endpoint) | ||
this.entropy = entropy | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I really don't think this should have
BITS
, I don't even know about thetolocaleString
.We want this to be CLI first, so just raw JSON friendly formats like numbers, objects, not sentences (number + unit).
I could be wrong!
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.
the utils method is the pure function that returns a number, my vision was that the controller/command file will handle how we want the data to be presented