-
Notifications
You must be signed in to change notification settings - Fork 92
feat: skip cells which has data or type when calculate balance #903
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9fe535b
feat: add hasData and typeScript to output entity
classicalliu 6a85705
feat: skip cells which has data or type
classicalliu abf8ae9
chore: only spent cells without data or type when gather inputs
classicalliu e334085
fix: change typeScript type to `text` from `varchar`
classicalliu 4b765b8
Merge remote-tracking branch 'origin/develop' into skip-data-and-type
classicalliu a952152
feat: add SkipDataAndType class
classicalliu 5746438
feat: add totalBalance to address entity
classicalliu f455545
feat: calculate totalBalance and check skip data and type in gather i…
classicalliu 834390f
feat: add controller for skip data and type
classicalliu 7a29c03
feat: add totalBalance to address interface
classicalliu af4ebcd
test: test cells service
classicalliu 90184aa
fix: add totalBalance to address test
classicalliu 4157306
chore: rename open to skip
classicalliu 11dcac7
fix: fix balance tests
classicalliu f852449
chore: rename open to skip in controller
classicalliu 06362a5
chore: update comment open => skip
classicalliu 37d82fb
feat: add base settings and move skip config to here
classicalliu 05683c6
chore: update comment
classicalliu 8a0bfff
chore: update comment
classicalliu 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
25 changes: 25 additions & 0 deletions
25
packages/neuron-wallet/src/controllers/skip-data-and-type.ts
This file contains hidden or 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,25 @@ | ||
| import { CatchControllerError } from 'decorators/errors' | ||
| import { ResponseCode } from 'utils/const' | ||
| import SkipDataAndType from 'services/settings/skip-data-and-type' | ||
|
|
||
| export default class SkipDataAndTypeController { | ||
| @CatchControllerError | ||
| public static async update(skip: boolean): Promise<Controller.Response<boolean>> { | ||
| SkipDataAndType.getInstance().update(skip) | ||
|
|
||
| return { | ||
| status: ResponseCode.Success, | ||
| result: skip, | ||
| } | ||
| } | ||
|
|
||
| @CatchControllerError | ||
| public static async get(): Promise<Controller.Response<boolean>> { | ||
| const skip = SkipDataAndType.getInstance().get() | ||
|
|
||
| return { | ||
| status: ResponseCode.Success, | ||
| result: skip, | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
17 changes: 17 additions & 0 deletions
17
packages/neuron-wallet/src/database/address/migrations/1567485550388-AddTotalBalance.ts
This file contains hidden or 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,17 @@ | ||
| import {MigrationInterface, QueryRunner, TableColumn} from "typeorm"; | ||
|
|
||
| export class AddTotalBalance1567485550388 implements MigrationInterface { | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<any> { | ||
| await queryRunner.addColumn('address', new TableColumn({ | ||
| name: 'totalBalance', | ||
| type: 'varchar', | ||
| default: '0', | ||
| })) | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<any> { | ||
| await queryRunner.dropColumn('address', 'totalBalance') | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
packages/neuron-wallet/src/database/chain/migrations/1567144517514-AddTypeAndHasData.ts
This file contains hidden or 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,24 @@ | ||
| import {MigrationInterface, QueryRunner, TableColumn} from "typeorm"; | ||
|
|
||
| export class AddTypeAndHasData1567144517514 implements MigrationInterface { | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<any> { | ||
| await queryRunner.addColumn('output', new TableColumn({ | ||
| name: 'typeScript', | ||
| type: 'text', | ||
| isNullable: true, | ||
| })) | ||
|
|
||
| await queryRunner.addColumn('output', new TableColumn({ | ||
| name: 'hasData', | ||
| type: 'boolean', | ||
| default: false, | ||
| })) | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<any> { | ||
| await queryRunner.dropColumn('output', 'hasData') | ||
| await queryRunner.dropColumn('output', 'typeScript') | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,48 @@ | ||
| import FileService from '../file' | ||
|
|
||
| export default class BaseSettings { | ||
| private static moduleName = '' | ||
| private static fileName = 'settings.json' | ||
|
|
||
| private static instance: BaseSettings | ||
|
|
||
| public static getInstance(): BaseSettings { | ||
| if (!BaseSettings.instance) { | ||
| BaseSettings.instance = new BaseSettings() | ||
| } | ||
|
|
||
| return BaseSettings.instance | ||
| } | ||
|
|
||
| public updateSetting = (key: string, value: any) => { | ||
| let settings = this.read() | ||
| if (settings === undefined) { | ||
| settings = {} | ||
| } | ||
| Object.assign(settings, { [key]: value }) | ||
| FileService.getInstance().writeFileSync(BaseSettings.moduleName, BaseSettings.fileName, JSON.stringify(settings)) | ||
| } | ||
|
|
||
| public getSetting = (key: string) => { | ||
| const info = this.read() | ||
|
|
||
| if (info) { | ||
| return info[key] | ||
| } | ||
|
|
||
| return undefined | ||
| } | ||
|
|
||
| public read = () => { | ||
| const fileService = FileService.getInstance() | ||
| const { moduleName, fileName } = BaseSettings | ||
|
|
||
| if (fileService.hasFile(moduleName, fileName)) { | ||
| const info = FileService.getInstance().readFileSync(moduleName, fileName) | ||
| const value = JSON.parse(info) | ||
| return value | ||
| } | ||
|
|
||
| return undefined | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
packages/neuron-wallet/src/services/settings/skip-data-and-type.ts
This file contains hidden or 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,39 @@ | ||
| import BaseSettings from './base' | ||
|
|
||
| export default class SkipDataAndType { | ||
| private skip: boolean | undefined = undefined | ||
| private keyName = 'skip' | ||
|
|
||
| private static instance: SkipDataAndType | ||
|
|
||
| static getInstance(): SkipDataAndType { | ||
| if (!SkipDataAndType.instance) { | ||
| SkipDataAndType.instance = new SkipDataAndType() | ||
| } | ||
|
|
||
| return SkipDataAndType.instance | ||
| } | ||
|
|
||
| // skip means can use cells with data and type | ||
| public update(skip: boolean) { | ||
| BaseSettings.getInstance().updateSetting(this.keyName, skip) | ||
| // cache this variable | ||
| this.skip = skip | ||
| } | ||
|
|
||
| public get(): boolean { | ||
| // if cached, don't read file | ||
| if (this.skip !== undefined) { | ||
| return this.skip | ||
| } | ||
|
|
||
| const skip = BaseSettings.getInstance().getSetting(this.keyName) | ||
|
|
||
| if (skip === false) { | ||
| return false | ||
| } | ||
|
|
||
| // default is true | ||
| return true | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.