Learn how to utilize Features to act as multiplex oracle for your contracts.
Please read the code comments in the files below. Examples are taken from our Example Contract Github repo.
// import the Feature superclass from the trac-peer packageimport {Feature} from'trac-peer';exportclassTimerextendsFeature {/** * Setup your Feature * * Instances of Features are passed to Peer instances. * See the Deployment section for more details. */constructor(peer, options = {}) {super(peer, options);this.update_interval =options.update_interval !==undefined&&false===isNaN(parseInt(options.update_interval)) &&parseInt(options.update_interval) >0?parseInt(options.update_interval) :60_000; }/** * start() is supposed to trigger the actual Feature execution. * * In the case of timers, an infinite event loop reads the latest * time every 10th second and appends it into the contract. * + The contract will then read this value as showcased in the previous * section. * * Appends from Features don't go through transactions but straight into * the contract. */asyncstart(options = {}) {while(true){awaitthis.append('currentTime',Date.now());awaitthis.sleep(this.update_interval); } }// stop helps to shutdown and may be triggered by a custom Feature-handlerasyncstop(options = {}) { }}exportdefault Timer;