@@ -2,10 +2,18 @@ var DashJoin = ('object' === typeof module && exports) || {};
22( function ( window , DashJoin ) {
33 'use strict' ;
44
5+ // let DashTx = window.DashTx || require('dashtx');
6+
57 const DENOM_LOWEST = 100001 ;
68 const PREDENOM_MIN = DENOM_LOWEST + 193 ;
79 const COLLATERAL = 10000 ; // DENOM_LOWEST / 10
10+ const PAYLOAD_SIZE_MAX = 4 * 1024 * 1024 ;
11+
12+ // https://github.com/dashpay/dash/blob/v19.x/src/coinjoin/coinjoin.h#L39
13+ // const COINJOIN_ENTRY_MAX_SIZE = 9; // real
14+ // const COINJOIN_ENTRY_MAX_SIZE = 2; // just for testing right now
815
16+ DashJoin . PAYLOAD_SIZE_MAX = PAYLOAD_SIZE_MAX ;
917 DashJoin . DENOM_LOWEST = DENOM_LOWEST ;
1018 DashJoin . COLLATERAL = COLLATERAL ;
1119 DashJoin . PREDENOM_MIN = PREDENOM_MIN ;
@@ -31,6 +39,91 @@ var DashJoin = ('object' === typeof module && exports) || {};
3139 return 0 ;
3240 } ;
3341
42+ DashJoin . utils = { } ;
43+
44+ DashJoin . utils . hexToBytes = function ( hex ) {
45+ let bufLen = hex . length / 2 ;
46+ let u8 = new Uint8Array ( bufLen ) ;
47+
48+ let i = 0 ;
49+ let index = 0 ;
50+ let lastIndex = hex . length - 2 ;
51+ for ( ; ; ) {
52+ if ( i > lastIndex ) {
53+ break ;
54+ }
55+
56+ let h = hex . slice ( i , i + 2 ) ;
57+ let b = parseInt ( h , 16 ) ;
58+ u8 [ index ] = b ;
59+
60+ i += 2 ;
61+ index += 1 ;
62+ }
63+
64+ return u8 ;
65+ } ;
66+
67+ DashJoin . utils . bytesToHex = function ( u8 ) {
68+ /** @type {Array<String> } */
69+ let hex = [ ] ;
70+
71+ u8 . forEach ( function ( b ) {
72+ let h = b . toString ( 16 ) . padStart ( 2 , '0' ) ;
73+ hex . push ( h ) ;
74+ } ) ;
75+
76+ return hex . join ( '' ) ;
77+ } ;
78+
79+ DashJoin . utils . _evonodeMapToList = function ( evonodesMap ) {
80+ console . log ( '[debug] get evonode list...' ) ;
81+ let evonodes = [ ] ;
82+ {
83+ //let resp = await rpc.masternodelist();
84+ let evonodeProTxIds = Object . keys ( evonodesMap ) ;
85+ for ( let id of evonodeProTxIds ) {
86+ let evonode = evonodesMap [ id ] ;
87+ if ( evonode . status !== 'ENABLED' ) {
88+ continue ;
89+ }
90+
91+ let hostParts = evonode . address . split ( ':' ) ;
92+ let evodata = {
93+ id : evonode . id ,
94+ host : evonode . address ,
95+ hostname : hostParts [ 0 ] ,
96+ port : hostParts [ 1 ] ,
97+ type : evonode . type ,
98+ } ;
99+ evonodes . push ( evodata ) ;
100+ }
101+ if ( ! evonodes . length ) {
102+ throw new Error ( 'Sanity Fail: no evonodes online' ) ;
103+ }
104+ }
105+
106+ // void shuffle(evonodes);
107+ evonodes . sort ( DashJoin . utils . sortMnListById ) ;
108+ return evonodes ;
109+ } ;
110+
111+ /**
112+ * @param {Object } a
113+ * @param {String } a.id
114+ * @param {Object } b
115+ * @param {String } b.id
116+ */
117+ DashJoin . utils . sortMnListById = function ( a , b ) {
118+ if ( a . id > b . id ) {
119+ return 1 ;
120+ }
121+ if ( a . id < b . id ) {
122+ return - 1 ;
123+ }
124+ return 0 ;
125+ } ;
126+
34127 //@ts -ignore
35128 window . DashJoin = DashJoin ;
36129} ) ( globalThis . window || { } , DashJoin ) ;
0 commit comments