]>
Commit | Line | Data |
---|---|---|
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 | ||
3501e4d2 | 19 | |
3ec03ada | 20 | #ifdef WIN32 |
21 | #define PACKED | |
22 | #else | |
23 | #define PACKED __attribute__((packed)) | |
24 | #endif | |
25 | ||
c1139e1e | 26 | #define KOMODO_EVENT_RATIFY 'P' |
3ec03ada | 27 | #define KOMODO_EVENT_NOTARIZED 'N' |
28 | #define KOMODO_EVENT_UTXO 'U' | |
29 | #define KOMODO_EVENT_KMDHEIGHT 'K' | |
30 | //#define KOMODO_EVENT_DELETE 'D' | |
31 | #define KOMODO_EVENT_PRICEFEED 'V' | |
32 | #define KOMODO_EVENT_OPRETURN 'R' | |
33 | #define KOMODO_OPRETURN_DEPOSIT 'D' | |
9d4a32f4 | 34 | #define KOMODO_OPRETURN_ISSUED 'I' // assetchain |
3ec03ada | 35 | #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain |
9d4a32f4 | 36 | #define KOMODO_OPRETURN_REDEEMED 'X' |
3ec03ada | 37 | |
bd787f59 | 38 | struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; |
39 | struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; }; | |
40 | struct komodo_event_utxo { uint256 txid; uint64_t voutmask; uint8_t numvouts; }; | |
41 | struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; }; | |
42 | struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; }; | |
3ec03ada | 43 | |
44 | struct komodo_event | |
45 | { | |
46 | struct komodo_event *related; | |
47 | uint16_t len; | |
48 | int32_t height; | |
49 | uint8_t type,reorged; | |
50 | char symbol[16]; | |
51 | uint8_t space[]; | |
52 | } PACKED; | |
53 | ||
c75c18fc | 54 | struct komodo_event **Komodo_events; int32_t Komodo_numevents; |
55 | ||
ea5742ed | 56 | struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) |
3ec03ada | 57 | { |
58 | struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); | |
ea5742ed | 59 | ep = (struct komodo_event *)calloc(1,len); |
3ec03ada | 60 | ep->len = len; |
61 | ep->height = height; | |
62 | ep->type = type; | |
63 | strcpy(ep->symbol,symbol); | |
64 | if ( datalen != 0 ) | |
65 | memcpy(ep->space,data,datalen); | |
40d4047d | 66 | Komodo_events = (struct komodo_event **)realloc(Komodo_events,(1 + Komodo_numevents) * sizeof(*Komodo_events)); |
c75c18fc | 67 | Komodo_events[Komodo_numevents++] = ep; |
3ec03ada | 68 | return(ep); |
69 | } | |
70 | ||
c75c18fc | 71 | void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) |
3ec03ada | 72 | { |
73 | struct komodo_event_notarized N; | |
74 | memset(&N,0,sizeof(N)); | |
40d4047d | 75 | N.blockhash = notarized_hash; |
76 | N.desttxid = notarized_desttxid; | |
3ec03ada | 77 | N.notarizedheight = notarizedheight; |
78 | strcpy(N.dest,dest); | |
c1139e1e | 79 | komodo_eventadd(height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); |
c75c18fc | 80 | if ( sp != 0 ) |
81 | komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid); | |
3ec03ada | 82 | } |
83 | ||
c75c18fc | 84 | void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) |
3ec03ada | 85 | { |
86 | struct komodo_event_pubkeys P; | |
87 | memset(&P,0,sizeof(P)); | |
88 | P.num = num; | |
89 | memcpy(P.pubkeys,pubkeys,33 * num); | |
c1139e1e | 90 | komodo_eventadd(height,symbol,KOMODO_EVENT_RATIFY,(uint8_t *)&P,(int32_t)(sizeof(P.num) + 33 * num)); |
c75c18fc | 91 | if ( sp != 0 ) |
92 | komodo_notarysinit(height,pubkeys,num); | |
3ec03ada | 93 | } |
94 | ||
6f3cb4d0 | 95 | /*void komodo_eventadd_utxo(struct komodo_state *sp,char *symbol,int32_t height,uint8_t notaryid,uint256 txid,uint64_t voutmask,uint8_t numvouts) |
3ec03ada | 96 | { |
97 | struct komodo_event_utxo U; | |
98 | memset(&U,0,sizeof(U)); | |
99 | U.txid = txid; | |
100 | U.voutmask = voutmask; | |
101 | U.numvouts = numvouts; | |
c1139e1e | 102 | komodo_eventadd(height,symbol,KOMODO_EVENT_UTXO,(uint8_t *)&U,sizeof(U)); |
c75c18fc | 103 | if ( sp != 0 ) |
104 | komodo_nutxoadd(height,notaryid,txid,voutmask,numvouts); | |
6f3cb4d0 | 105 | }*/ |
3ec03ada | 106 | |
c75c18fc | 107 | void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num) |
3ec03ada | 108 | { |
109 | struct komodo_event_pricefeed F; | |
110 | memset(&F,0,sizeof(F)); | |
111 | F.num = num; | |
112 | memcpy(F.prices,prices,sizeof(*F.prices) * num); | |
928dfe4e | 113 | komodo_eventadd(height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num)); |
c75c18fc | 114 | if ( sp != 0 ) |
115 | komodo_pvals(height,prices,num); | |
3ec03ada | 116 | } |
117 | ||
c75c18fc | 118 | void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight) |
3ec03ada | 119 | { |
c1139e1e | 120 | komodo_eventadd(height,symbol,KOMODO_EVENT_KMDHEIGHT,(uint8_t *)&kmdheight,sizeof(kmdheight)); |
c75c18fc | 121 | if ( sp != 0 ) |
122 | komodo_setkmdheight(kmdheight); | |
3ec03ada | 123 | } |
124 | ||
40d4047d | 125 | void 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 | 126 | { |
127 | struct komodo_event_opreturn O; uint8_t opret[10000]; | |
128 | memset(&O,0,sizeof(O)); | |
129 | O.txid = txid; | |
130 | O.value = value; | |
131 | O.vout = vout; | |
132 | memcpy(opret,&O,sizeof(O)); | |
c1139e1e | 133 | memcpy(&opret[sizeof(O)],buf,opretlen); |
928dfe4e | 134 | O.oplen = (int32_t)(opretlen + sizeof(O)); |
c75c18fc | 135 | komodo_eventadd(height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen); |
136 | if ( sp != 0 ) | |
137 | komodo_opreturn(height,value,buf,opretlen,txid,vout); | |
138 | } | |
139 | ||
140 | void komodo_event_undo(struct komodo_event *ep) | |
141 | { | |
142 | switch ( ep->type ) | |
143 | { | |
144 | case KOMODO_EVENT_RATIFY: | |
145 | case KOMODO_EVENT_NOTARIZED: | |
146 | case KOMODO_EVENT_UTXO: | |
147 | case KOMODO_EVENT_KMDHEIGHT: | |
148 | case KOMODO_EVENT_PRICEFEED: | |
149 | case KOMODO_EVENT_OPRETURN: | |
150 | break; | |
151 | } | |
3ec03ada | 152 | } |
153 | ||
c75c18fc | 154 | void komodo_event_rewind(int32_t height) |
155 | { | |
40d4047d | 156 | struct komodo_event *ep; |
c75c18fc | 157 | while ( Komodo_numevents > 0 ) |
158 | { | |
159 | if ( (ep= Komodo_events[Komodo_numevents-1]) != 0 ) | |
160 | { | |
161 | if ( ep->height < height ) | |
162 | break; | |
163 | komodo_event_undo(ep); | |
164 | Komodo_numevents--; | |
165 | } | |
166 | } | |
167 | } | |
168 | ||
169 | /*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 | 170 | { |
171 | uint8_t opret[512]; uint16_t opretlen; | |
a882d643 | 172 | komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen); |
3ec03ada | 173 | } |
174 | ||
c75c18fc | 175 | void 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 | 176 | { |
177 | uint8_t opret[512]; uint16_t opretlen; | |
a882d643 | 178 | komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen); |
3ec03ada | 179 | } |
180 | ||
c75c18fc | 181 | void 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 | 182 | { |
183 | uint8_t opret[512]; uint16_t opretlen; | |
a882d643 | 184 | komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen); |
3ec03ada | 185 | } |
186 | ||
c75c18fc | 187 | void 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 | 188 | { |
189 | uint8_t opret[512]; uint16_t opretlen; | |
a882d643 | 190 | komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen); |
c75c18fc | 191 | }*/ |
3ec03ada | 192 | |
193 | // process events | |
194 | // | |
3501e4d2 | 195 | |
3ec03ada | 196 | #endif |