You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.6 KiB

  1. // Copyright 2017-2018 DERO Project. All rights reserved.
  2. // Use of this source code in any form is governed by RESEARCH license.
  3. // license can be found in the LICENSE file.
  4. // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
  5. //
  6. //
  7. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  8. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  10. // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  13. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  14. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  15. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. package inputmaturity
  17. import "time"
  18. import "github.com/deroproject/derosuite/config"
  19. //this file implements the logic to detect whether an input is mature or still locked
  20. //This function is crucial as any bugs can have catastrophic effects
  21. //this function is used both by the core blockchain and wallet
  22. //TODO we need to check the edge cases
  23. func Is_Input_Mature(current_chain_height uint64, input_block_height uint64, locked_to_height uint64, sigtype uint64) bool {
  24. // current_chain_height must be greater or equal to input height
  25. if current_chain_height < input_block_height { // wrong cases reject
  26. return false
  27. }
  28. // all miner txs end up here
  29. if sigtype == 0 { // miner tx will also always unlock 60 blocks in future
  30. if current_chain_height >= (input_block_height + config.MINER_TX_AMOUNT_UNLOCK) {
  31. return true
  32. }
  33. return false
  34. }
  35. // 99.99 % normal tx cases come here
  36. if locked_to_height == 0 { // input is not locked, so it must be unlocked in 10 blocks
  37. if current_chain_height >= (input_block_height + config.NORMAL_TX_AMOUNT_UNLOCK) {
  38. return true
  39. }
  40. return false
  41. }
  42. // input_block_height is no longer useful
  43. // if we are here input was locked to specific height or time
  44. if locked_to_height < config.CRYPTONOTE_MAX_BLOCK_NUMBER { // input was locked to specific block height
  45. if current_chain_height >= locked_to_height {
  46. return true
  47. }
  48. return false
  49. }
  50. // anything above LIMIT is time based lock
  51. // input was locked to specific time in epoch
  52. if locked_to_height < (uint64(time.Now().UTC().Unix())) {
  53. return true
  54. }
  55. return false // reject time based locks if not mature
  56. }