Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 0bf15a6

Browse files
asimm241janniks
andauthored
feat: transfer existing subdomains to new addresses (#88)
* feat: add support for transfer endpoint for subdomain migration * fix: convert to wrapped public key * fix: update address version * chore: fix hash data * fix: update public key format and error message * fix: set seqn to 1 * test: add transfer test Co-authored-by: janniks <[email protected]>
1 parent 2443e75 commit 0bf15a6

File tree

8 files changed

+601
-179
lines changed

8 files changed

+601
-179
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ typings/
5858
# dotenv environment variables file
5959
.env
6060

61+
.DS_Store
6162
data
6263
lib
6364
tests/lib
6465
.vscode
6566
package-lock.json
67+
*.db

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"blockstack": "^21.1.1",
1414
"bn.js": "^4.11.9",
1515
"cors": "^2.8.4",
16+
"crypto": "^1.0.1",
1617
"express": "^4.16.2",
1718
"node-fetch": "^2.6.7",
1819
"prom-client": "^11.5.3",

src/db.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,46 @@ export class RegistrarQueueDB {
214214
return dbRun(this.db, dbCmd, dbArgs)
215215
}
216216

217+
async makeTransferUpdates(
218+
transferedSubdomains: QueueRecord[],
219+
txHash: string
220+
): Promise<void> {
221+
const dbCmd =
222+
'INSERT INTO subdomain_queue ' +
223+
'(subdomainName, owner, sequenceNumber, zonefile, signature, status, status_more) VALUES ' +
224+
'(?, ?, ?, ?, ?, ?, ?)'
225+
226+
Promise.all(transferedSubdomains.map((subdomain) => dbRun(this.db, dbCmd, [
227+
subdomain.subdomainName,
228+
subdomain.owner,
229+
subdomain.sequenceNumber,
230+
subdomain.zonefile,
231+
subdomain.signature,
232+
'submitted',
233+
txHash
234+
])))
235+
}
236+
237+
logTransferRequestorData(
238+
subdomainName: string,
239+
ownerAddress: string,
240+
ipAddress: string
241+
) {
242+
const lookup = `SELECT queue_ix FROM subdomain_queue WHERE subdomainName = ?
243+
AND owner = ? AND sequenceNumber = 1`
244+
const insert =
245+
'INSERT INTO ip_info (ip_address, owner, queue_ix) VALUES (?, ?, ?)'
246+
return dbAll(this.db, lookup, [subdomainName, ownerAddress]).then(
247+
(results) => {
248+
if (results.length != 1) {
249+
throw new Error('No queued entry found.')
250+
}
251+
const queueIndex = results[0].queue_ix
252+
return dbRun(this.db, insert, [ipAddress, ownerAddress, queueIndex])
253+
}
254+
)
255+
}
256+
217257
async updateStatusFor(
218258
subdomains: Array<string>,
219259
status: string,
@@ -291,6 +331,29 @@ export class RegistrarQueueDB {
291331
return dbAll(this.db, lookup, [subdomainName])
292332
}
293333

334+
async getSubdomainRecord(subdomainName: string): Promise<SubdomainRecord> {
335+
const lookup =
336+
'SELECT subdomainName, owner, sequenceNumber, zonefile, signature, status, queue_ix' +
337+
' FROM subdomain_queue' +
338+
' WHERE subdomainName = ? ORDER BY queue_ix DESC LIMIT 1'
339+
340+
const result = await dbAll(this.db, lookup, [subdomainName])
341+
342+
if (result.length != 1) {
343+
throw new Error('no subdomain found')
344+
}
345+
return {
346+
subdomainName: result[0].subdomainName,
347+
owner: result[0].owner,
348+
sequenceNumber: parseInt(result[0].sequenceNumber),
349+
zonefile: result[0].zonefile,
350+
signature: result[0].signature,
351+
status: result[0].status,
352+
queue_ix: result[0].queue_ix
353+
}
354+
355+
}
356+
294357
async listSubdomains(
295358
iterator: number,
296359
timeLimit: number

0 commit comments

Comments
 (0)