JoinSEEDS / seeds-smart-contracts

Smart contracts for SEEDS - A Regenerative Civilization Building Game.
https://docs.google.com/document/d/1C4w9Ol8VGabCIcQDVPDrwcTRoJXBqhrb7VjslwQbUGU/edit#heading=h.6f4sxygso816
MIT License
20 stars 6 forks source link

Fix cyclestats start_time and end_time using moon cycle times #412

Closed n13 closed 2 years ago

n13 commented 2 years ago

Why

Currently cycle stats start time is set to whenever onperiod is run end_time is set to 29.5 days after

This is because in the past, we did not have actual moon cycle times on contract. We were estimating.

Fix

On onPeriod, search for the closest new moon to the now() time, for the start Then set end to the next New Moon after that

Using the moonphases tables in the cycle.seeds contract.

https://telos.bloks.io/account/cycle.seeds?loadContract=true&tab=Tables&account=cycle.seeds&scope=cycle.seeds&limit=100&table=moonphases

How (suggestion)

1 - when onperiod is run, take the now() time, and subtract say 5 days in seconds from it (meaning it works as long as onperiod was run within 5 days of the new moon) 2 - use this value as lower bound search 3 - iterate until the next new moon, use as start, 4 - iterate more until second new moon, use as end

Cleos example to illustrate bounds search

cleosm --print-request get table cycle.seeds cycle.seeds moonphases --lower 982906450 --limit 1
REQUEST:
---------------------
POST /v1/chain/get_table_rows HTTP/1.0
Host: node.hypha.earth
content-length: 287
Accept: */*
Connection: close

{
  "json": true,
  "code": "cycle.seeds",
  "scope": "cycle.seeds",
  "table": "moonphases",
  "table_key": "",
  "lower_bound": "982906450",
  "upper_bound": "",
  "limit": 1,
  "key_type": "",
  "index_position": "",
  "encode_type": "dec",
  "reverse": false,
  "show_payer": false
}
---------------------
{
  "rows": [{
      "timestamp": 982916460,
      "time": "2001-02-23T08:21:00.000",
      "phase_name": "New Moon",
      "eclipse": ""
    }
  ],
  "more": true,
  "next_key": "983584980"
}