Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- blockno: block that the trade is executed
- input: param of the network.trade()
- - value (msg.value, ether amount that was sent along with the tx)
- - owner (the address that made the trade)
- - gas_price
- - source
- - srcAmount
- - dest
- - destAddress
- - maxDestAmount
- - minConversionRate
- - walletID
- - reserves (list of existing reserves at blockno)
- network_issues: array of issues []string
- reserve_issues: map of reserve to array of issues map[reserve][]string
- function debug(input, blockno) returns (network_issues and reserve_issues) {
- init network_issues
- init reserve_issues
- // simple network scope checks
- if input.gas_price > wrapperGetGasCap(input, blockno) {
- "gas price exceeded max limit" -> network_issues
- }
- if input.source is token {
- if input.value > 0 {
- "failed because of sending ether along the tx when it is trying to trade token to ether" -> network_issues
- }
- if allowance(input.source, input.owner) < input.srcAmount {
- "failed because allowance is lower than srcAmount" -> network_issues
- }
- if balance(input.source, input.owner) < input.srcAmount {
- "failed because token balance is lower than srcAmount" -> network_issues
- }
- } else it is ether {
- if input.value != input.srcAmount {
- "failed because the user didn't send the exact amount of ether along" -> network_issues
- }
- }
- if input.source is ether {
- if input.srcAmount > wrapperGetUserCap(input, blockno) {
- "failed because the source amount exceeded user cap" -> network_issues
- }
- }
- if input.dest is ether {
- if input.destAmount > wrapperGetUserCap(input, blockno) {
- "failed because the dest amount exceeded user cap" -> network_issues
- }
- }
- // taking into reserve scope
- rates = wrapperGetConversionRate(reserve, input, blockno) for all reserve in input.reserves
- if all rates are 0 {
- "no reserve was chosen because all returned rates are 0" -> network_issues
- for reserve in input.reserves {
- reasons = wrapperGetReasons(reserve, input, blockno)
- if len(reasons) == 0 {
- // we can't really tell what is the reason
- "is block volume cap and volume between prices changes" -> reserve_issues[reserve]
- } else {
- reasons -> reserve_issues[reserve]
- }
- }
- } else {
- // there is at least one reserve is chosen
- chosenReserve = wrapperGetChosenReserve(input, blockno)
- wrapperGetReasons(reserve, input) -> reserve_issues[reserve]
- }
- return network_issues and reserve_issues
- }
- Wrapper functions:
- wrapperGetGasCap(input, blockno)
- wrapperGetUserCap(input, blockno)
- wrapperGetConversionRate(reserve, input, blockno)
- wrapperGetChosenReserve(input, blockno)
- wrapperGetReasons(reserve, input, blockno) returns one or more of following reasons:
- - trade is disabled in reserve level
- - volume limit exceeded
- - some internal configuration errors by the operator (just a validation)
- - price exceeds sanity price
- - price was not updated in last X blocks
Add Comment
Please, Sign In to add comment