Skip to content

Commit 3589732

Browse files
committed
Add allowExisting option for name_new.
In namecoin/namecoin-core#54, it was suggested to disallow name_new for already existing names in the RPC interface by default (while of course still allowing those on the consensus level). This change leverages the new "options" argument for name_new to implement this: We add a new "allowExisting" option in the JSON object, false by default, and raise an error for name_new with an existing name unless this option is explicitly set to true.
1 parent 8fc3973 commit 3589732

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

doc/release-notes-namecoin.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@
3434
name RPCs like `name_show` or `name_scan`.
3535
See the [proposal](https://github.com/namecoin/namecoin-core/issues/219) and
3636
the [implementation](https://github.com/namecoin/namecoin-core/pull/236).
37+
38+
- `name_new` now checks whether a name exists already and by default rejects
39+
to register an already existing name. To override this check and get back
40+
the old behaviour (where a `NAME_NEW` transaction can be sent for existing
41+
names), set the new `allowExisting` option to true.
42+
For more context, see the
43+
[corresponding issue](https://github.com/namecoin/namecoin-core/issues/54).

src/wallet/rpcnames.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ name_new (const JSONRPCRequest& request)
357357
"1. \"name\" (string, required) the name to register\n"
358358
"2. \"options\" (object, optional)\n"
359359
+ NameOpOptionsHelpBuilder ()
360+
.withField ("\"allowExisting\"",
361+
"(boolean, optional, default=false) If set, then the"
362+
" name_new is sent even if the name exists already")
360363
.finish ("") +
361364
"\nResult:\n"
362365
"[\n"
@@ -378,6 +381,19 @@ name_new (const JSONRPCRequest& request)
378381
UniValue options(UniValue::VOBJ);
379382
if (request.params.size () >= 2)
380383
options = request.params[1].get_obj ();
384+
RPCTypeCheckObj (options,
385+
{
386+
{"allowExisting", UniValueType (UniValue::VBOOL)},
387+
},
388+
true, false);
389+
390+
if (!options["allowExisting"].isTrue ())
391+
{
392+
LOCK (cs_main);
393+
CNameData oldData;
394+
if (pcoinsTip->GetName (name, oldData) && !oldData.isExpired ())
395+
throw JSONRPCError (RPC_TRANSACTION_ERROR, "this name exists already");
396+
}
381397

382398
valtype rand(20);
383399
GetRandBytes (&rand[0], rand.size ());

test/functional/name_registration.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ def run_test (self):
7171
self.checkNameHistory (1, "node-0", ["value-0"])
7272
self.checkNameHistory (1, "node-1", ["x" * 520])
7373

74+
# Verify the allowExisting option for name_new.
75+
assert_raises_rpc_error (-25, 'exists already',
76+
self.nodes[0].name_new, "node-0")
77+
assert_raises_rpc_error (-25, 'exists already',
78+
self.nodes[0].name_new, "node-0",
79+
{"allowExisting": False})
80+
assert_raises_rpc_error (-3, 'Expected type bool for allowExisting',
81+
self.nodes[0].name_new, "other",
82+
{"allowExisting": 42.5})
83+
self.nodes[0].name_new ("node-0", {"allowExisting": True})
84+
7485
# Check for error with rand mismatch (wrong name)
7586
newA = self.nodes[0].name_new ("test-name")
7687
self.generate (0, 10)
@@ -86,8 +97,8 @@ def run_test (self):
8697
self.firstupdateName (0, "test-name", newA, "test-value")
8798

8899
# Check for disallowed firstupdate when the name is active.
89-
newSteal = self.nodes[1].name_new ("node-0")
90-
newSteal2 = self.nodes[1].name_new ("node-0")
100+
newSteal = self.nodes[1].name_new ("node-0", {"allowExisting": True})
101+
newSteal2 = self.nodes[1].name_new ("node-0", {"allowExisting": True})
91102
self.generate (0, 19)
92103
self.checkName (1, "node-0", "value-0", 1, False)
93104
assert_raises_rpc_error (-25, 'this name is already active',

0 commit comments

Comments
 (0)