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

Transfer existing subdomains to new addresses #88

Merged
merged 7 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ typings/
# dotenv environment variables file
.env

.DS_Store
data
lib
tests/lib
.vscode
package-lock.json
*.db
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"blockstack": "^21.1.1",
"bn.js": "^4.11.9",
"cors": "^2.8.4",
"crypto": "^1.0.1",
"express": "^4.16.2",
"node-fetch": "^2.6.7",
"prom-client": "^11.5.3",
Expand Down
63 changes: 63 additions & 0 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,46 @@ export class RegistrarQueueDB {
return dbRun(this.db, dbCmd, dbArgs)
}

async makeTransferUpdates(
transferedSubdomains: QueueRecord[],
txHash: string
): Promise<void> {
const dbCmd =
'INSERT INTO subdomain_queue ' +
'(subdomainName, owner, sequenceNumber, zonefile, signature, status, status_more) VALUES ' +
'(?, ?, ?, ?, ?, ?, ?)'

Promise.all(transferedSubdomains.map((subdomain) => dbRun(this.db, dbCmd, [
subdomain.subdomainName,
subdomain.owner,
subdomain.sequenceNumber,
subdomain.zonefile,
subdomain.signature,
'submitted',
txHash
])))
}

logTransferRequestorData(
subdomainName: string,
ownerAddress: string,
ipAddress: string
) {
const lookup = `SELECT queue_ix FROM subdomain_queue WHERE subdomainName = ?
AND owner = ? AND sequenceNumber = 1`
const insert =
'INSERT INTO ip_info (ip_address, owner, queue_ix) VALUES (?, ?, ?)'
return dbAll(this.db, lookup, [subdomainName, ownerAddress]).then(
(results) => {
if (results.length != 1) {
throw new Error('No queued entry found.')
}
const queueIndex = results[0].queue_ix
return dbRun(this.db, insert, [ipAddress, ownerAddress, queueIndex])
}
)
}

async updateStatusFor(
subdomains: Array<string>,
status: string,
Expand Down Expand Up @@ -291,6 +331,29 @@ export class RegistrarQueueDB {
return dbAll(this.db, lookup, [subdomainName])
}

async getSubdomainRecord(subdomainName: string): Promise<SubdomainRecord> {
const lookup =
'SELECT subdomainName, owner, sequenceNumber, zonefile, signature, status, queue_ix' +
' FROM subdomain_queue' +
' WHERE subdomainName = ? ORDER BY queue_ix DESC LIMIT 1'

const result = await dbAll(this.db, lookup, [subdomainName])

if (result.length != 1) {
throw new Error('no subdomain found')
}
return {
subdomainName: result[0].subdomainName,
owner: result[0].owner,
sequenceNumber: parseInt(result[0].sequenceNumber),
zonefile: result[0].zonefile,
signature: result[0].signature,
status: result[0].status,
queue_ix: result[0].queue_ix
}

}

async listSubdomains(
iterator: number,
timeLimit: number
Expand Down
Loading