Skip to content

Commit

Permalink
propagated hsd PR 499 (handshake-org#499) into here
Browse files Browse the repository at this point in the history
Signed-off-by: rozaydin <ridvan@namebase.io>
  • Loading branch information
rozaydin committed Mar 4, 2021
1 parent 95b0f40 commit df57fde
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 42 deletions.
2 changes: 0 additions & 2 deletions lib/primitives/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ class Address extends bio.Struct {
throw new Error('Object is not an address.');

if (Buffer.isBuffer(data)) {
if (data.length !== 20 && data.length !== 32)
throw new Error('Object is not an address.');
return data;
}

Expand Down
1 change: 0 additions & 1 deletion lib/wallet/txdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,6 @@ class TXDB {
ns.applyState(delta);

if (ns.isNull()) {
await this.removeNameMap(b, nameHash);
b.del(layout.A.encode(nameHash));
} else {
b.put(layout.A.encode(nameHash), ns.encode());
Expand Down
15 changes: 11 additions & 4 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,8 @@ class Wallet extends EventEmitter {
async _importName(name) {
const nameHash = rules.hashName(name);

if (await this.txdb.hasNameState(nameHash))
throw new Error('Name already exists.');
// if (await this.txdb.hasNameState(nameHash))
// throw new Error('Name already exists.');

const b = this.db.batch();
await this.wdb.addNameMap(b, nameHash, this.wid);
Expand Down Expand Up @@ -1715,7 +1715,10 @@ class Wallet extends EventEmitter {
continue;
}

const addr = await this.receiveAddress(acct);
const addr = Address.fromNulldata(Buffer.alloc(2));
try {
await this.importName(name);
} catch (err) { /** swallow the case where an expired name re-opened */ }

const output = new Output();
output.address = addr;
Expand All @@ -1730,6 +1733,10 @@ class Wallet extends EventEmitter {
continue;
}

// const b = this.db.batch();
// await this.wdb.addNameMap(b, nameHash, this.wid);
// await b.write();

mtx.outputs.push(output);
}

Expand All @@ -1749,7 +1756,7 @@ class Wallet extends EventEmitter {
async _createBatchOpen(names, force, options) {
const acct = options ? options.account || 0 : 0;
const {mtx, errors, isAllError} = await this
.makeBatchOpen(names, force, acct);
.makeBatchOpen(names, force, acct);
if (!isAllError) {
await this.fill(mtx, options);
const finalizedMtx = await this.finalize(mtx, options);
Expand Down
15 changes: 4 additions & 11 deletions test/wallet-importname-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,8 @@ describe('Wallet Import Name', function() {
assert(ns4 === null);
});

it('should not re-import an existing name', async () => {
await assert.rejects(
alice.importName(name),
{message: 'Name already exists.'}
);
it('should ignore re-importing existing name', async () => {
await alice.importName(name);
});

it('should bid on names from Alice\'s wallet', async () => {
Expand Down Expand Up @@ -223,13 +220,9 @@ describe('Wallet Import Name', function() {
assert(!bid.own);
});

it('should not re-import name', async () => {
it('should ignore re-importing name', async () => {
await wclient.execute('selectwallet', ['charlie']);

await assert.rejects(
wclient.execute('importname', [name, 0]),
{message: 'Name already exists.'}
);
await wclient.execute('importname', [name, 0]);
});
});
});
48 changes: 24 additions & 24 deletions test/wallet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 2);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.coin, 1); // OPENs are sent to a null address
assert.strictEqual(bal.confirmed, fund);
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, 0);
Expand All @@ -2030,7 +2030,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 2);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.coin, 1);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, 0);
Expand All @@ -2047,7 +2047,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 3);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, lockup);
Expand All @@ -2065,7 +2065,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 3);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, lockup);
Expand All @@ -2082,7 +2082,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 4);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, value);
Expand All @@ -2100,7 +2100,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 4);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, value);
Expand Down Expand Up @@ -2145,7 +2145,7 @@ describe('Wallet', function() {
assert.strictEqual(bal.tx, 5);
// Wallet coin count doesn't change:
// REVEAL + fee money -> REGISTER + change
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2163,7 +2163,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 5);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2178,7 +2178,7 @@ describe('Wallet', function() {
// Check
const senderBal1 = await wallet.getBalance();
assert.strictEqual(senderBal1.tx, 6);
assert.strictEqual(senderBal1.coin, 4);
assert.strictEqual(senderBal1.coin, 3);
assert.strictEqual(senderBal1.confirmed, fund - (cTXCount * fee));
assert.strictEqual(senderBal1.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(senderBal1.ulocked, secondHighest);
Expand All @@ -2204,7 +2204,7 @@ describe('Wallet', function() {
// Check
const senderBal2 = await wallet.getBalance();
assert.strictEqual(senderBal2.tx, 6);
assert.strictEqual(senderBal2.coin, 4);
assert.strictEqual(senderBal2.coin, 3);
assert.strictEqual(senderBal2.confirmed, fund - (cTXCount * fee));
assert.strictEqual(senderBal2.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(senderBal2.ulocked, secondHighest);
Expand All @@ -2230,7 +2230,7 @@ describe('Wallet', function() {
const senderBal3 = await wallet.getBalance();
assert.strictEqual(senderBal3.tx, 7);
// One less wallet coin because name UTXO belongs to recip now
assert.strictEqual(senderBal3.coin, 3);
assert.strictEqual(senderBal3.coin, 2);
assert.strictEqual(senderBal3.confirmed, fund - (cTXCount * fee));
assert.strictEqual(senderBal3.unconfirmed, fund - secondHighest - (uTXCount * fee));
assert.strictEqual(senderBal3.ulocked, 0);
Expand Down Expand Up @@ -2259,7 +2259,7 @@ describe('Wallet', function() {
// Check
senderBalBefore = await wallet.getBalance();
assert.strictEqual(senderBalBefore.tx, 7);
assert.strictEqual(senderBalBefore.coin, 3);
assert.strictEqual(senderBalBefore.coin, 2);
assert.strictEqual(senderBalBefore.confirmed, fund - secondHighest - (cTXCount * fee));
assert.strictEqual(senderBalBefore.unconfirmed, fund - secondHighest - (uTXCount * fee));
assert.strictEqual(senderBalBefore.ulocked, 0);
Expand Down Expand Up @@ -2292,7 +2292,7 @@ describe('Wallet', function() {
// Check
const senderBal4 = await wallet.getBalance();
assert.strictEqual(senderBal4.tx, 7);
assert.strictEqual(senderBal4.coin, 3);
assert.strictEqual(senderBal4.coin, 2);
assert.strictEqual(senderBal4.confirmed, fund - (cTXCount * fee));
assert.strictEqual(senderBal4.unconfirmed, fund - secondHighest - (uTXCount * fee));
assert.strictEqual(senderBal4.ulocked, 0);
Expand Down Expand Up @@ -2396,7 +2396,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 2);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.coin, 1);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, 0);
Expand All @@ -2412,7 +2412,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 2);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.coin, 1);
assert.strictEqual(bal.confirmed, 10e6 - (1 * fee));
assert.strictEqual(bal.unconfirmed, 10e6 - (1 * fee));
assert.strictEqual(bal.ulocked, 0);
Expand All @@ -2431,7 +2431,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 3);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, lockup);
Expand All @@ -2447,7 +2447,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 3);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, 10e6 - (2 * fee));
assert.strictEqual(bal.unconfirmed, 10e6 - (2 * fee));
assert.strictEqual(bal.ulocked, lockup);
Expand All @@ -2466,7 +2466,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 4);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, value);
Expand Down Expand Up @@ -2508,7 +2508,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 4);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, 10e6 - (3 * fee));
assert.strictEqual(bal.unconfirmed, 10e6 - (3 * fee));
assert.strictEqual(bal.ulocked, value);
Expand All @@ -2529,7 +2529,7 @@ describe('Wallet', function() {
assert.strictEqual(bal.tx, 5);
// Wallet coin count doesn't change:
// REVEAL + fee money -> REGISTER + change
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2546,7 +2546,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 5);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2565,7 +2565,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 6);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2581,7 +2581,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 6);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2601,7 +2601,7 @@ describe('Wallet', function() {
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 7);
// Coin count reduced by giving away name UTXO
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, fund - secondHighest - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - secondHighest - (uTXCount * fee));
assert.strictEqual(bal.ulocked, 0);
Expand Down

0 comments on commit df57fde

Please sign in to comment.