Skip to content

Commit

Permalink
feat: WOOT! got dsc with the new code. Huzzah!
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Aug 17, 2024
1 parent 19b856b commit dc7223c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
2 changes: 2 additions & 0 deletions public/dashjoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ var DashJoin = ('object' === typeof module && exports) || {};
let session_id = DashTx.utils.bytesToHex(sessionId);
offset += Sizes.SESSION_ID;

console.log('DEBUG [[dsf]] bytes', DashTx.utils.bytesToHex(bytes));
let transactionUnsigned = bytes.subarray(offset);
let transaction_unsigned = DashTx.utils.bytesToHex(transactionUnsigned);
console.log('DEBUG [[dsf]] tx', transaction_unsigned);
Expand All @@ -405,6 +406,7 @@ var DashJoin = ('object' === typeof module && exports) || {};
inputs: txRequest.inputs,
outputs: txRequest.outputs,
locktime: txRequest.locktime,
transaction_unsigned: transaction_unsigned,
};
return dsfTxRequest;
};
Expand Down
12 changes: 6 additions & 6 deletions public/dashp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ var DashP2P = ('object' === typeof module && exports) || {};

void (await evstream.once('version'));
console.log('%c[[version]] PROCESSED', 'color: red');
void (await evstream.once('verack'));
console.log('%c[[verack]] PROCESSED', 'color: red');
// void (await evstream.once('verack'));
// console.log('%c[[verack]] PROCESSED', 'color: red');

(async function () {
for (;;) {
Expand Down Expand Up @@ -551,7 +551,7 @@ var DashP2P = ('object' === typeof module && exports) || {};
addr_recv_port, // required to match
addr_trans_services = [],
addr_trans_ip = '127.0.0.1',
addr_trans_port = 65535,
addr_trans_port = Math.ceil(65535 * Math.random()),
start_height,
nonce = null,
user_agent = null,
Expand Down Expand Up @@ -998,17 +998,17 @@ var DashP2P = ('object' === typeof module && exports) || {};
}

if (eventname) {
p.events = [eventname];
p._events = [eventname];
} else if (defaultEvents?.length) {
p.events = defaultEvents;
p._events = defaultEvents;
} else {
let err = new Error(
`call stream.createSubscriber(['*']) or conn.once('*') for default events`,
);
Object.assign(err, { code: 'E_NO_EVENTS' });
throw err;
}
console.log('%c[[RESUB]]', 'color: red; font-weight: bold;', p.events);
console.log('%c[[RESUB]]', 'color: red; font-weight: bold;', p._events);

return await p._next();
};
Expand Down
49 changes: 34 additions & 15 deletions public/wallet-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
// let address;
let address = txInput.address;
if (!address) {
let pkhBytes = DashKeys.utils.hexToBytes(txInput.pubKeyHash);
address = await DashKeys.pkhToAddr(pkhBytes, { version: network });
return null;
// let pkhBytes = DashKeys.utils.hexToBytes(txInput.pubKeyHash);
// address = await DashKeys.pkhToAddr(pkhBytes, { version: network });
}

let yourKeyData = keysMap[address];
Expand Down Expand Up @@ -116,26 +117,30 @@
let spendableAddrs = Object.keys(deltasMap);
for (let address of spendableAddrs) {
let info = deltasMap[address];
if (info.balance === 0) {
continue;
}
for (let coin of info.deltas) {
if (coin.reserved > 0) {
continue;
}
info.balance = DashTx.sum(info.deltas);

for (let coin of info.deltas) {
let addressInfo = keysMap[coin.address];
Object.assign(coin, {
outputIndex: coin.index,
denom: DashJoin.getDenom(coin.satoshis),
publicKey: addressInfo.publicKey,
pubKeyHash: addressInfo.pubKeyHash,
});

if (coin.reserved > 0) {
continue;
}

if (opts?.denom === false) {
if (coin.denom) {
continue;
}
}

if (info.balance === 0) {
break;
}
utxos.push(coin);
}
}
Expand Down Expand Up @@ -1084,7 +1089,8 @@
);
});

function cleanup() {
function cleanup(err) {
console.error('WebSocket Error:', err);
delete App.peers[evonode.host];
for (let denom of DashJoin.DENOMS) {
delete App.coinjoinQueues[denom][evonode.host];
Expand Down Expand Up @@ -1186,8 +1192,9 @@
});
p2p.send(dsiBytes);
let msg = await evstream.once('dsf');
let dsf = DashJoin.parsers.dsf(msg.payload);
console.log('DEBUG dsf', dsf);
console.log('DEBUG dsf %c[[MSG]]', 'color: blue', msg);
let dsfTxRequest = DashJoin.parsers.dsf(msg.payload);
console.log('DEBUG dsf', dsfTxRequest, inputs);

makeSelectedInputsSignable(dsfTxRequest, inputs);
let txSigned = await dashTx.hashAndSignAll(dsfTxRequest);
Expand Down Expand Up @@ -1231,6 +1238,8 @@

let sigHashType = DashTx.SIGHASH_ALL | DashTx.SIGHASH_ANYONECANPAY; //jshint ignore:line

console.log(sighashInput);
console.log(input);
sighashInput.index = input.index;
sighashInput.address = input.address;
sighashInput.satoshis = input.satoshis;
Expand Down Expand Up @@ -1275,6 +1284,8 @@
}
}

App.peers = {};

async function main() {
if (network === `testnet`) {
let $testnets = $$('[data-network=testnet]');
Expand All @@ -1293,8 +1304,17 @@
App._chaininfo = await rpc('getblockchaininfo');
console.log(App._rawmnlist);
App._evonodes = DashJoin.utils._evonodeMapToList(App._rawmnlist);
App._evonode = App._evonodes.at(-13);
console.info('[info] chosen evonode:');
// 35.166.18.166:19999
let index = 5;
// let index = Math.floor(Math.random() * App._evonodes.length);
// App._evonode = App._evonodes[index];
App._evonode = App._evonodes.at(index);
// App._evonode = {
// host: '35.166.18.166:19999',
// hostname: '35.166.18.166',
// port: '19999',
// };
console.info('[info] chosen evonode:', index);
console.log(JSON.stringify(App._evonode, null, 2));

App.coinjoinQueues = {
Expand All @@ -1304,7 +1324,6 @@
100001000: {}, // 1.00001000
1000010000: {}, // 10.00010000
};
App.peers = {};

void (await connectToPeer(App._evonode, App._chaininfo.blocks));
}
Expand Down

0 comments on commit dc7223c

Please sign in to comment.