]> Git Repo - VerusCoin.git/blame - src/komodo_events.h
Test
[VerusCoin.git] / src / komodo_events.h
CommitLineData
3ec03ada 1/******************************************************************************
713c2a94 2 * Copyright © 2014-2018 The SuperNET Developers. *
3ec03ada 3 * *
4 * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
5 * the top-level directory of this distribution for the individual copyright *
6 * holder information and the developer policies on copyright and licensing. *
7 * *
8 * Unless otherwise agreed in a custom licensing agreement, no part of the *
9 * SuperNET software, including this file may be copied, modified, propagated *
10 * or distributed except according to the terms contained in the LICENSE file *
11 * *
12 * Removal or modification of this copyright notice is prohibited. *
13 * *
14 ******************************************************************************/
15
16#ifndef H_KOMODOEVENTS_H
17#define H_KOMODOEVENTS_H
5416af1d 18#include "komodo_defs.h"
3ec03ada 19
ab918767 20struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen)
3ec03ada 21{
36ec445a 22 struct komodo_event *ep=0; uint16_t len = (uint16_t)(sizeof(*ep) + datalen);
23 if ( sp != 0 )
24 {
25 portable_mutex_lock(&komodo_mutex);
26 ep = (struct komodo_event *)calloc(1,len);
27 ep->len = len;
28 ep->height = height;
29 ep->type = type;
30 strcpy(ep->symbol,symbol);
31 if ( datalen != 0 )
32 memcpy(ep->space,data,datalen);
33 sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events));
34 sp->Komodo_events[sp->Komodo_numevents++] = ep;
35 portable_mutex_unlock(&komodo_mutex);
36 }
3ec03ada 37 return(ep);
38}
39
18c6cfce 40void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight,uint256 MoM,int32_t MoMdepth)
3ec03ada 41{
42 struct komodo_event_notarized N;
6a933d59 43 if ( NOTARY_PUBKEY33[0] != 0 && komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 )
17914f3e 44 {
a4f48f00 45 if ( height > 50000 || ASSETCHAINS_SYMBOL[0] != 0 )
c452b1d7 46 printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest);
17914f3e 47 }
605e7794 48 else
13b64fd6 49 {
05c1e522 50 if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
a4f48f00 51 fprintf(stderr,"validated [%s] ht.%d notarized %d\n",ASSETCHAINS_SYMBOL,height,notarizedheight);
13b64fd6 52 memset(&N,0,sizeof(N));
53 N.blockhash = notarized_hash;
54 N.desttxid = notarized_desttxid;
55 N.notarizedheight = notarizedheight;
18c6cfce 56 N.MoM = MoM;
57 N.MoMdepth = MoMdepth;
13b64fd6 58 strcpy(N.dest,dest);
ed937645 59 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N));
13b64fd6 60 if ( sp != 0 )
18c6cfce 61 komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid,MoM,MoMdepth);
13b64fd6 62 }
3ec03ada 63}
64
c75c18fc 65void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33])
3ec03ada 66{
67 struct komodo_event_pubkeys P;
3f8696e5 68 //printf("eventadd pubkeys ht.%d\n",height);
3ec03ada 69 memset(&P,0,sizeof(P));
70 P.num = num;
71 memcpy(P.pubkeys,pubkeys,33 * num);
ab918767 72 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_RATIFY,(uint8_t *)&P,(int32_t)(sizeof(P.num) + 33 * num));
c75c18fc 73 if ( sp != 0 )
74 komodo_notarysinit(height,pubkeys,num);
3ec03ada 75}
76
c75c18fc 77void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num)
3ec03ada 78{
79 struct komodo_event_pricefeed F;
80 memset(&F,0,sizeof(F));
81 F.num = num;
82 memcpy(F.prices,prices,sizeof(*F.prices) * num);
ab918767 83 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num));
c75c18fc 84 if ( sp != 0 )
85 komodo_pvals(height,prices,num);
3ec03ada 86}
87
40d4047d 88void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t height,uint256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen)
3ec03ada 89{
ef1a9636 90 struct komodo_event_opreturn O; uint8_t opret[16384];
3ec03ada 91 memset(&O,0,sizeof(O));
92 O.txid = txid;
93 O.value = value;
94 O.vout = vout;
95 memcpy(opret,&O,sizeof(O));
c1139e1e 96 memcpy(&opret[sizeof(O)],buf,opretlen);
928dfe4e 97 O.oplen = (int32_t)(opretlen + sizeof(O));
ab918767 98 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen);
c75c18fc 99 if ( sp != 0 )
cd26c1f3 100 komodo_opreturn(height,value,buf,opretlen,txid,vout,symbol);
c75c18fc 101}
102
ab918767 103void komodo_event_undo(struct komodo_state *sp,struct komodo_event *ep)
c75c18fc 104{
105 switch ( ep->type )
106 {
ab918767 107 case KOMODO_EVENT_RATIFY: printf("rewind of ratify, needs to be coded.%d\n",ep->height); break;
37fed603 108 case KOMODO_EVENT_NOTARIZED: break;
c75c18fc 109 case KOMODO_EVENT_KMDHEIGHT:
ab918767 110 if ( ep->height <= sp->SAVEDHEIGHT )
111 sp->SAVEDHEIGHT = ep->height;
112 break;
c75c18fc 113 case KOMODO_EVENT_PRICEFEED:
ab918767 114 // backtrack prices;
115 break;
c75c18fc 116 case KOMODO_EVENT_OPRETURN:
ab918767 117 // backtrack opreturns
c75c18fc 118 break;
119 }
3ec03ada 120}
121
f3a1de3a 122void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height)
c75c18fc 123{
40d4047d 124 struct komodo_event *ep;
f3a1de3a 125 if ( sp != 0 )
c75c18fc 126 {
8ee93080 127 if ( ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_LASTMINED && prevKOMODO_LASTMINED != 0 )
128 {
129 printf("undo KOMODO_LASTMINED %d <- %d\n",KOMODO_LASTMINED,prevKOMODO_LASTMINED);
130 KOMODO_LASTMINED = prevKOMODO_LASTMINED;
131 prevKOMODO_LASTMINED = 0;
132 }
ab918767 133 while ( sp->Komodo_events != 0 && sp->Komodo_numevents > 0 )
c75c18fc 134 {
ab918767 135 if ( (ep= sp->Komodo_events[sp->Komodo_numevents-1]) != 0 )
f3a1de3a 136 {
137 if ( ep->height < height )
138 break;
48a3cd18 139 //printf("[%s] undo %s event.%c ht.%d for rewind.%d\n",ASSETCHAINS_SYMBOL,symbol,ep->type,ep->height,height);
ab918767 140 komodo_event_undo(sp,ep);
141 sp->Komodo_numevents--;
f3a1de3a 142 }
c75c18fc 143 }
144 }
145}
146
e155dbe9 147void komodo_setkmdheight(struct komodo_state *sp,int32_t kmdheight,uint32_t timestamp)
ab918767 148{
36ec445a 149 if ( sp != 0 )
e155dbe9 150 {
36ec445a 151 if ( kmdheight > sp->SAVEDHEIGHT )
152 {
153 sp->SAVEDHEIGHT = kmdheight;
154 sp->SAVEDTIMESTAMP = timestamp;
155 }
156 if ( kmdheight > sp->CURRENT_HEIGHT )
157 sp->CURRENT_HEIGHT = kmdheight;
e155dbe9 158 }
ab918767 159}
160
e155dbe9 161void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight,uint32_t timestamp)
ab918767 162{
e155dbe9 163 uint32_t buf[2];
ab918767 164 if ( kmdheight > 0 )
165 {
e155dbe9 166 buf[0] = (uint32_t)kmdheight;
167 buf[1] = timestamp;
168 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_KMDHEIGHT,(uint8_t *)buf,sizeof(buf));
ab918767 169 if ( sp != 0 )
e155dbe9 170 komodo_setkmdheight(sp,kmdheight,timestamp);
ab918767 171 }
172 else
173 {
dfd07d78 174 //fprintf(stderr,"REWIND kmdheight.%d\n",kmdheight);
ab918767 175 kmdheight = -kmdheight;
2b983c80 176 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_REWIND,(uint8_t *)&height,sizeof(height));
ab918767 177 if ( sp != 0 )
178 komodo_event_rewind(sp,symbol,height);
179 }
180}
181
182
c75c18fc 183/*void komodo_eventadd_deposit(int32_t actionflag,char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price)
3ec03ada 184{
185 uint8_t opret[512]; uint16_t opretlen;
a882d643 186 komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen);
3ec03ada 187}
188
c75c18fc 189void komodo_eventadd_issued(int32_t actionflag,char *symbol,int32_t height,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,bits256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis)
3ec03ada 190{
191 uint8_t opret[512]; uint16_t opretlen;
a882d643 192 komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen);
3ec03ada 193}
194
c75c18fc 195void komodo_eventadd_withdraw(int32_t actionflag,char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 fiattxid,int32_t fiatvout,uint64_t price)
3ec03ada 196{
197 uint8_t opret[512]; uint16_t opretlen;
a882d643 198 komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen);
3ec03ada 199}
200
c75c18fc 201void komodo_eventadd_redeemed(int32_t actionflag,char *symbol,int32_t height,bits256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,uint64_t komodoshis)
3ec03ada 202{
203 uint8_t opret[512]; uint16_t opretlen;
a882d643 204 komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen);
c75c18fc 205}*/
3ec03ada 206
207// process events
208//
3501e4d2 209
3ec03ada 210#endif
This page took 0.209911 seconds and 4 git commands to generate.