Guest User

Untitled

a guest
Jan 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. blockno: block that the trade is executed
  2.  
  3. input: param of the network.trade()
  4. - value (msg.value, ether amount that was sent along with the tx)
  5. - owner (the address that made the trade)
  6. - gas_price
  7. - source
  8. - srcAmount
  9. - dest
  10. - destAddress
  11. - maxDestAmount
  12. - minConversionRate
  13. - walletID
  14. - reserves (list of existing reserves at blockno)
  15.  
  16. network_issues: array of issues []string
  17.  
  18. reserve_issues: map of reserve to array of issues map[reserve][]string
  19.  
  20.  
  21. function debug(input, blockno) returns (network_issues and reserve_issues) {
  22. init network_issues
  23. init reserve_issues
  24.  
  25. // simple network scope checks
  26.  
  27. if input.gas_price > wrapperGetGasCap(input, blockno) {
  28. "gas price exceeded max limit" -> network_issues
  29. }
  30.  
  31. if input.source is token {
  32. if input.value > 0 {
  33. "failed because of sending ether along the tx when it is trying to trade token to ether" -> network_issues
  34. }
  35. if allowance(input.source, input.owner) < input.srcAmount {
  36. "failed because allowance is lower than srcAmount" -> network_issues
  37. }
  38. if balance(input.source, input.owner) < input.srcAmount {
  39. "failed because token balance is lower than srcAmount" -> network_issues
  40. }
  41. } else it is ether {
  42. if input.value != input.srcAmount {
  43. "failed because the user didn't send the exact amount of ether along" -> network_issues
  44. }
  45. }
  46.  
  47. if input.source is ether {
  48. if input.srcAmount > wrapperGetUserCap(input, blockno) {
  49. "failed because the source amount exceeded user cap" -> network_issues
  50. }
  51. }
  52. if input.dest is ether {
  53. if input.destAmount > wrapperGetUserCap(input, blockno) {
  54. "failed because the dest amount exceeded user cap" -> network_issues
  55. }
  56. }
  57.  
  58. // taking into reserve scope
  59. rates = wrapperGetConversionRate(reserve, input, blockno) for all reserve in input.reserves
  60. if all rates are 0 {
  61. "no reserve was chosen because all returned rates are 0" -> network_issues
  62. for reserve in input.reserves {
  63. reasons = wrapperGetReasons(reserve, input, blockno)
  64. if len(reasons) == 0 {
  65. // we can't really tell what is the reason
  66. "is block volume cap and volume between prices changes" -> reserve_issues[reserve]
  67. } else {
  68. reasons -> reserve_issues[reserve]
  69. }
  70. }
  71. } else {
  72. // there is at least one reserve is chosen
  73. chosenReserve = wrapperGetChosenReserve(input, blockno)
  74. wrapperGetReasons(reserve, input) -> reserve_issues[reserve]
  75. }
  76.  
  77. return network_issues and reserve_issues
  78. }
  79.  
  80.  
  81. Wrapper functions:
  82. wrapperGetGasCap(input, blockno)
  83. wrapperGetUserCap(input, blockno)
  84. wrapperGetConversionRate(reserve, input, blockno)
  85. wrapperGetChosenReserve(input, blockno)
  86. wrapperGetReasons(reserve, input, blockno) returns one or more of following reasons:
  87. - trade is disabled in reserve level
  88. - volume limit exceeded
  89. - some internal configuration errors by the operator (just a validation)
  90. - price exceeds sanity price
  91. - price was not updated in last X blocks
Add Comment
Please, Sign In to add comment