]> Git Repo - VerusCoin.git/blame - src/komodo_events.h
test
[VerusCoin.git] / src / komodo_events.h
CommitLineData
3ec03ada 1/******************************************************************************
2 * Copyright © 2014-2016 The SuperNET Developers. *
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
18
ab918767 19struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen)
3ec03ada 20{
36ec445a 21 struct komodo_event *ep=0; uint16_t len = (uint16_t)(sizeof(*ep) + datalen);
22 if ( sp != 0 )
23 {
24 portable_mutex_lock(&komodo_mutex);
25 ep = (struct komodo_event *)calloc(1,len);
26 ep->len = len;
27 ep->height = height;
28 ep->type = type;
29 strcpy(ep->symbol,symbol);
30 if ( datalen != 0 )
31 memcpy(ep->space,data,datalen);
32 sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events));
33 sp->Komodo_events[sp->Komodo_numevents++] = ep;
34 portable_mutex_unlock(&komodo_mutex);
35 }
3ec03ada 36 return(ep);
37}
38
c75c18fc 39void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight)
3ec03ada 40{
41 struct komodo_event_notarized N;
42 memset(&N,0,sizeof(N));
40d4047d 43 N.blockhash = notarized_hash;
44 N.desttxid = notarized_desttxid;
3ec03ada 45 N.notarizedheight = notarizedheight;
46 strcpy(N.dest,dest);
ab918767 47 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N));
c75c18fc 48 if ( sp != 0 )
49 komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid);
3ec03ada 50}
51
c75c18fc 52void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33])
3ec03ada 53{
54 struct komodo_event_pubkeys P;
f3a1de3a 55 printf("eventadd pubkeys ht.%d\n",height);
3ec03ada 56 memset(&P,0,sizeof(P));
57 P.num = num;
58 memcpy(P.pubkeys,pubkeys,33 * num);
ab918767 59 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_RATIFY,(uint8_t *)&P,(int32_t)(sizeof(P.num) + 33 * num));
c75c18fc 60 if ( sp != 0 )
61 komodo_notarysinit(height,pubkeys,num);
3ec03ada 62}
63
c75c18fc 64void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num)
3ec03ada 65{
66 struct komodo_event_pricefeed F;
67 memset(&F,0,sizeof(F));
68 F.num = num;
69 memcpy(F.prices,prices,sizeof(*F.prices) * num);
ab918767 70 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num));
c75c18fc 71 if ( sp != 0 )
72 komodo_pvals(height,prices,num);
3ec03ada 73}
74
40d4047d 75void 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 76{
ef1a9636 77 struct komodo_event_opreturn O; uint8_t opret[16384];
3ec03ada 78 memset(&O,0,sizeof(O));
79 O.txid = txid;
80 O.value = value;
81 O.vout = vout;
82 memcpy(opret,&O,sizeof(O));
c1139e1e 83 memcpy(&opret[sizeof(O)],buf,opretlen);
928dfe4e 84 O.oplen = (int32_t)(opretlen + sizeof(O));
ab918767 85 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen);
c75c18fc 86 if ( sp != 0 )
cd26c1f3 87 komodo_opreturn(height,value,buf,opretlen,txid,vout,symbol);
c75c18fc 88}
89
ab918767 90void komodo_event_undo(struct komodo_state *sp,struct komodo_event *ep)
c75c18fc 91{
92 switch ( ep->type )
93 {
ab918767 94 case KOMODO_EVENT_RATIFY: printf("rewind of ratify, needs to be coded.%d\n",ep->height); break;
95 case KOMODO_EVENT_NOTARIZED: printf("unexpected rewind of notarization.%d\n",ep->height); break;
c75c18fc 96 case KOMODO_EVENT_KMDHEIGHT:
ab918767 97 if ( ep->height <= sp->SAVEDHEIGHT )
98 sp->SAVEDHEIGHT = ep->height;
99 break;
c75c18fc 100 case KOMODO_EVENT_PRICEFEED:
ab918767 101 // backtrack prices;
102 break;
c75c18fc 103 case KOMODO_EVENT_OPRETURN:
ab918767 104 // backtrack opreturns
c75c18fc 105 break;
106 }
3ec03ada 107}
108
f3a1de3a 109void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height)
c75c18fc 110{
40d4047d 111 struct komodo_event *ep;
f3a1de3a 112 if ( sp != 0 )
c75c18fc 113 {
ab918767 114 while ( sp->Komodo_events != 0 && sp->Komodo_numevents > 0 )
c75c18fc 115 {
ab918767 116 if ( (ep= sp->Komodo_events[sp->Komodo_numevents-1]) != 0 )
f3a1de3a 117 {
118 if ( ep->height < height )
119 break;
48a3cd18 120 //printf("[%s] undo %s event.%c ht.%d for rewind.%d\n",ASSETCHAINS_SYMBOL,symbol,ep->type,ep->height,height);
ab918767 121 komodo_event_undo(sp,ep);
122 sp->Komodo_numevents--;
f3a1de3a 123 }
c75c18fc 124 }
125 }
126}
127
e155dbe9 128void komodo_setkmdheight(struct komodo_state *sp,int32_t kmdheight,uint32_t timestamp)
ab918767 129{
36ec445a 130 if ( sp != 0 )
e155dbe9 131 {
36ec445a 132 if ( kmdheight > sp->SAVEDHEIGHT )
133 {
134 sp->SAVEDHEIGHT = kmdheight;
135 sp->SAVEDTIMESTAMP = timestamp;
136 }
137 if ( kmdheight > sp->CURRENT_HEIGHT )
138 sp->CURRENT_HEIGHT = kmdheight;
e155dbe9 139 }
ab918767 140}
141
e155dbe9 142void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight,uint32_t timestamp)
ab918767 143{
e155dbe9 144 uint32_t buf[2];
ab918767 145 if ( kmdheight > 0 )
146 {
e155dbe9 147 buf[0] = (uint32_t)kmdheight;
148 buf[1] = timestamp;
149 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_KMDHEIGHT,(uint8_t *)buf,sizeof(buf));
ab918767 150 if ( sp != 0 )
e155dbe9 151 komodo_setkmdheight(sp,kmdheight,timestamp);
ab918767 152 }
153 else
154 {
155 kmdheight = -kmdheight;
2b983c80 156 komodo_eventadd(sp,height,symbol,KOMODO_EVENT_REWIND,(uint8_t *)&height,sizeof(height));
ab918767 157 if ( sp != 0 )
158 komodo_event_rewind(sp,symbol,height);
159 }
160}
161
162
c75c18fc 163/*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 164{
165 uint8_t opret[512]; uint16_t opretlen;
a882d643 166 komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen);
3ec03ada 167}
168
c75c18fc 169void 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 170{
171 uint8_t opret[512]; uint16_t opretlen;
a882d643 172 komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen);
3ec03ada 173}
174
c75c18fc 175void 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 176{
177 uint8_t opret[512]; uint16_t opretlen;
a882d643 178 komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen);
3ec03ada 179}
180
c75c18fc 181void 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 182{
183 uint8_t opret[512]; uint16_t opretlen;
a882d643 184 komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen);
c75c18fc 185}*/
3ec03ada 186
187// process events
188//
3501e4d2 189
3ec03ada 190#endif
This page took 0.073623 seconds and 4 git commands to generate.