forked from rsksmart/rif-relay
-
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.
OG-134 Not ready yet is not informative (#498)
* OG-134 Not ready yet is not informative Also, some progress on OG-139 as logs are improved throughout the relaying code (WIP) 1. Remove 'StateError' as a way to bail out when not ready. 2. Create 'AmountRequired' to maybe save on suplicate logic piece (meeting some ETH value criteria)
- Loading branch information
Showing
21 changed files
with
1,808 additions
and
1,262 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
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,71 @@ | ||
// @ts-ignore | ||
import EthVal from 'ethval' | ||
import log from 'loglevel' | ||
import { toBN } from 'web3-utils' | ||
import { boolString } from './Utils' | ||
|
||
export class AmountRequired { | ||
_name: string | ||
_currentValue = toBN(0) | ||
_requiredValue = toBN(0) | ||
_listener?: () => void | ||
|
||
constructor (name: string, requiredValue: BN, listener?: () => void) { | ||
this._name = name | ||
this._requiredValue = requiredValue | ||
this._listener = listener | ||
} | ||
|
||
get currentValue (): BN { | ||
return this._currentValue | ||
} | ||
|
||
set currentValue (newValue: BN) { | ||
const didChange = !this._currentValue.eq(newValue) | ||
const wasSatisfied = this.isSatisfied | ||
this._currentValue = newValue | ||
if (didChange) { | ||
this._onChange(wasSatisfied) | ||
} | ||
} | ||
|
||
get requiredValue (): BN { | ||
return this._requiredValue | ||
} | ||
|
||
set requiredValue (newValue: BN) { | ||
const didChange = !this._requiredValue.eq(newValue) | ||
const wasSatisfied = this.isSatisfied | ||
this._requiredValue = newValue | ||
if (didChange) { | ||
this._onChange(wasSatisfied) | ||
} | ||
} | ||
|
||
_onChange (wasSatisfied: boolean): void { | ||
let changeString | ||
if (wasSatisfied === this.isSatisfied) { | ||
changeString = `still${this.isSatisfied ? '' : ' not'}` | ||
} else if (this.isSatisfied) { | ||
changeString = 'now' | ||
} else { | ||
changeString = 'no longer' | ||
} | ||
const message = `${this._name} requirement is ${changeString} satisfied\n${this.description}` | ||
log.warn(message) | ||
if (this._listener != null) { | ||
this._listener() | ||
} | ||
} | ||
|
||
get isSatisfied (): boolean { | ||
return this._currentValue.gte(this._requiredValue) | ||
} | ||
|
||
get description (): string { | ||
const status = boolString(this.isSatisfied) | ||
const actual: string = new EthVal(this._currentValue).toEth().toFixed(4) | ||
const required: string = new EthVal(this._requiredValue).toEth().toFixed(4) | ||
return `${this._name.padEnd(14)} | ${status.padEnd(14)} | actual: ${actual.padStart(12)} ETH | required: ${required.padStart(12)} ETH` | ||
} | ||
} |
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
Oops, something went wrong.