Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register, search, names, and more #5

Merged
merged 93 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
6154319
add "api" script in root
ryanwaits Jun 7, 2023
0ef03e0
add radix-ui/react-slot
ryanwaits Jun 7, 2023
6442e87
update yaml lock
ryanwaits Jun 7, 2023
f5f8754
update hashFqn to use hash160 and match the hashFqn in tests module
ryanwaits Jun 7, 2023
136c32a
add new tailwind components
ryanwaits Jun 7, 2023
2a815dd
add ability to register bns name
ryanwaits Jun 7, 2023
3bd6292
add jest types
ryanwaits Jun 8, 2023
ab70f63
add rounded-full to match original button design
ryanwaits Jun 8, 2023
109e3da
add register page/component
ryanwaits Jun 8, 2023
d373ede
feat: include raw namespace properties in `@bns-x/core` package
hstove Jun 12, 2023
687239d
feat: tests for namespace pricing functions
hstove Jun 14, 2023
a025e04
merge tailwind button components
ryanwaits Jun 18, 2023
2f99b01
update imports for Button
ryanwaits Jun 18, 2023
7262063
temp: comment out unused Beutton
ryanwaits Jun 18, 2023
27bd88a
add list component for displaying namespaces
ryanwaits Jun 18, 2023
bbd2f76
update register page to list multiple namespaces and dynamically search
ryanwaits Jun 18, 2023
01ca0c4
install sonner for toasts
ryanwaits Jun 18, 2023
c274502
add state for register tx
ryanwaits Jun 18, 2023
b5385f8
create useNameRegister hook for easier reusability
ryanwaits Jun 18, 2023
95c5ea7
refactor to use hooks and toast on register
ryanwaits Jun 18, 2023
dd83c37
add post conditions to name register
ryanwaits Jun 19, 2023
82ba396
add devnet and testnet namespace
ryanwaits Jun 27, 2023
95e4f1e
use hexToString to convert to string if necessary
ryanwaits Jun 27, 2023
c41c175
add available namespaces to atom store
ryanwaits Jun 27, 2023
ef0224c
update to use helpers
ryanwaits Jun 27, 2023
f25cd0f
use namespace store
ryanwaits Jun 27, 2023
0d51a19
reset profile code
ryanwaits Jun 27, 2023
70c1a95
use computePrice func
ryanwaits Jun 27, 2023
2a3a91c
update copy from claim to register
ryanwaits Jun 27, 2023
fdb3b97
fix: mocknet url for scripts
hstove Jun 19, 2023
94d5b43
fix: api type for trpc getNameDetails
hstove Jul 13, 2023
69ee1c1
feat: setup shadcn-ui cli
hstove Jul 13, 2023
21a9769
feat: btc namespace first, basic name validation helper
hstove Jul 13, 2023
f57234f
feat: use shadcn table for name rows
hstove Jul 13, 2023
d4d2ba7
feat: remove unused code from name row
hstove Jul 13, 2023
9f9d205
feat: deploy and config registrar on mainnet/testnet
hstove Jul 13, 2023
b683cfe
feat: more efficient API call for checking name availability
hstove Jul 13, 2023
ea06c68
feat: improved debouncing/state for search
hstove Aug 3, 2023
69daa9b
chore: remove commented import
hstove Aug 10, 2023
d5b54ec
feat: success state for registration
hstove Aug 10, 2023
3366d91
feat: new migrator contract
hstove Aug 3, 2023
ed3313d
feat: bridge contract started, wrap/signing functionality
hstove Aug 4, 2023
8e4bdeb
feat: scripting setup for `ord` on regtest
hstove Aug 7, 2023
1608374
feat: update bridge-v1 signature validation logic
hstove Aug 7, 2023
25325a0
feat: init of web page for wrapping
hstove Aug 7, 2023
dc5aa60
feat: contract helper to migrate and bridge
hstove Aug 8, 2023
3693554
feat: trigger tx for bridging
hstove Aug 8, 2023
3b74a91
feat: improved contract api for bridging
hstove Aug 8, 2023
6414d02
fix: conflicts from merge
hstove Aug 10, 2023
364655a
feat: start of bridge unwrap flow and tests
hstove Aug 10, 2023
a5a0431
feat: bridge-to-l2 contract method, tests
hstove Aug 11, 2023
350da92
fix: name owned by address api
hstove Aug 11, 2023
9d2bcf4
feat: DB, routes for inscribed names
hstove Aug 11, 2023
0075633
feat: bridge wrap tx page
hstove Aug 11, 2023
522944c
feat: trpc route for inscriptionId->name lookup
hstove Aug 11, 2023
0e805fb
feat: v1 of ordinal card
hstove Aug 15, 2023
67af968
feat: clean up ord card
hstove Aug 15, 2023
d4278e6
feat: build script for ord template
hstove Aug 15, 2023
5ae0fae
feat: authorization management for bridge
hstove Aug 15, 2023
111fdd8
feat: start of unwrap page
hstove Aug 15, 2023
05c4c5e
feat: moved bridge-related utils to new package
hstove Aug 16, 2023
c126913
feat: end-to-end flow for bridging to L2
hstove Aug 16, 2023
9bd1118
feat: scripting to deploy card source
hstove Aug 21, 2023
7b8b899
feat: v1 of wrapper deployer
hstove Aug 21, 2023
c56e9f1
feat: integrate figma tokens in tailwind
hstove Aug 22, 2023
86d0c46
fix: bootstrap script timing
hstove Aug 22, 2023
f9fd882
feat: tailwind-based Text component
hstove Aug 22, 2023
5ff9f52
fix: conflicting text component classes
hstove Aug 22, 2023
c91e7ce
feat: error handling with inscription input
hstove Aug 23, 2023
dce68ff
feat: basic table for recent bridged names
hstove Aug 23, 2023
fb2fae0
feat: links to bridge a name
hstove Aug 24, 2023
1f5e32b
feat: better actions for names list
hstove Aug 24, 2023
bf77b74
feat: layout tweaks
hstove Aug 24, 2023
4fb8f43
feat: rename path from names/:name to manage/:name
hstove Aug 25, 2023
6b19747
feat: rename name management components
hstove Aug 25, 2023
f233653
feat: name page
hstove Aug 25, 2023
19a2685
feat: trpc endpoint to search names
hstove Aug 26, 2023
5d8fc67
feat: names search ui
hstove Aug 26, 2023
33333ad
feat: setup css vars for shadcn
hstove Aug 26, 2023
b9809a9
feat: update command/dialog components
hstove Aug 26, 2023
37dc2b4
fix: proper form on faucet page
hstove Aug 26, 2023
8ea8e8d
feat: debounced search
hstove Aug 26, 2023
ea38ff4
feat: name page improvements
hstove Aug 28, 2023
65ae4f4
feat: inscription details on name page
hstove Aug 28, 2023
4bce301
chore: update lockfile version
hstove Aug 29, 2023
f9ea1a6
feat: bridge from sub-accounts
hstove Aug 29, 2023
640cdae
feat: import more color tokens
hstove Aug 30, 2023
9d0b496
feat: add feature flag for l1
hstove Sep 6, 2023
f23581b
fix: type error on nostr page
hstove Sep 6, 2023
e36fba1
fix: include bridge package in dockerfile
hstove Sep 6, 2023
2de3bc6
fix: build packages script in dockerfile
hstove Sep 6, 2023
b626943
fix: bundling config for bridge pkg
hstove Sep 6, 2023
a7be163
fix: update name page when search changed
hstove Sep 6, 2023
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
5 changes: 5 additions & 0 deletions .changeset/blue-phones-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'web': minor
---

Dots now includes a "registration" page, where you can easily register a name on any namespace.
12 changes: 12 additions & 0 deletions .changeset/cyan-seas-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@bns-x/core': minor
'contracts': minor
---

A new migrator contract, `wrapper-migrator-v2` has been added.

The key change for this contract is that it uses Clarity 2.0 functions. Specifically, the `to-consensus-buff?` method is used to hash a wrapper contract's identifier, which can be used to verify signatures.

Previously, the migrator relied on the wrapper contract "registering" itself, which would allow mapping a wrapper principal to an integer. Prior to Clarity 2, integers were one of the only data types that could be hashed.

The main benefit of this new contract is that it is less faulty to re-orgs when multiple wrapper contracts are deployed. Previously, in some cases, a re-org could cause a wrapper contracts "ID" to change, which would invalidate signatures. Additionally, migrations can now occur before wrapper contract deployments are confirmed.
5 changes: 5 additions & 0 deletions .changeset/fresh-hairs-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bns-x/core': patch
---

Adds client-side namespace properties, which are pulled from on-chain data.
5 changes: 5 additions & 0 deletions .changeset/late-clocks-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bns-x/api': patch
---

Fixes an issue where the name owned by an address was wrong when the BNS name had been transferred away from the address
5 changes: 5 additions & 0 deletions .changeset/lovely-glasses-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bns-x/api': patch
---

Adds DB schema and trpc endpoints to fetch bridged names, as well as to lookup an inscription ID for a given name.
5 changes: 5 additions & 0 deletions .changeset/two-pumas-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bns-x/api': patch
---

Includes explicit types for `getNameDetails` TRPC endpoint
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ tests
contracts/dscripts
contracts/tests
contracts/dep-tests
contracts/deno
contracts/vendor
dep-tests
*.d.ts
dist
dist
web/tw-conf
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"contracts/dep-tests",
"contracts/deps.ts",
"contracts/dscripts",
"contracts/tests"
"contracts/tests",
"contracts/deno",
"contracts/vendor",
],
"files.eol": "\n",
"typescript.preferences.importModuleSpecifier": "non-relative",
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ COPY web/package.json web/
COPY packages/core/package.json packages/core/
COPY packages/client/package.json packages/client/
COPY packages/api-types/package.json packages/api-types/
COPY packages/bridge/package.json packages/bridge/
COPY packages/punycode/package.json packages/punycode/
COPY web/patches web/patches

COPY . .

RUN CI=true pnpm install --frozen-lockfile --shamefully-hoist

COPY . .

RUN pnpm --filter @bns-x/api prebuild

RUN pnpm turbo run build --filter @bns-x/api
RUN pnpm build:packages

COPY api/scripts/docker-entrypoint.sh docker-entrypoint.sh

Expand Down
3 changes: 3 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
"author": "Hank Stoever",
"license": "ISC",
"dependencies": {
"@bns-x/client": "workspace:*",
"@bns-x/core": "workspace:*",
"@bns-x/punycode": "workspace:*",
"@clarigen/core": "1.0.14",
"@clarigen/node": "1.0.14",
"@fastify/cors": "^8.2.0",
"@fastify/http-proxy": "8.4.0",
"@fastify/schedule": "^4.1.1",
"@fastify/static": "^6.6.1",
"@fastify/swagger": "^8.3.1",
"@fastify/swagger-ui": "^1.4.0",
Expand Down Expand Up @@ -70,6 +72,7 @@
"punycode": "^2.1.1",
"socket.io-client": "^4.4.1",
"stacks-encoding-native-js": "1.0.0",
"toad-scheduler": "^3.0.0",
"trpc-openapi": "^1.1.2",
"trpc-openapi-fork-fastify-pr-177": "^1.1.2",
"trpc-playground": "^1.0.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
CREATE MATERIALIZED VIEW inscribed_names as
with last_ids as (
select
distinct on (value ->> 'id')
value->>'account' as account
, value->>'id' as id
, value->>'inscriptionId' as inscription_id
, "blockHeight" as block_height
, "microblockSequence" as microblock_sequence
, "txIndex" as tx_index
, "eventIndex" as event_index
, txid
FROM "PrintEvent"
where "contractId" like '%.l1-registry'
and value->>'topic' = 'wrap'
and "microblockCanonical" = true
and "canonical" = true
order by
value->>'id'
, "blockHeight" desc
, "microblockSequence" desc
, "txIndex" desc
, "eventIndex" desc
),

unwraps as (
select
distinct on (value->>'id')
value->>'id' as id
from "PrintEvent"
where "contractId" like '%.l1-registry'
and value->>'topic' = 'unwrap'
and "microblockCanonical" = true
and "canonical" = true
order by
value->>'id'
, "blockHeight" desc
, "microblockSequence" desc
, "txIndex" desc
, "eventIndex" desc
)

select
distinct on (p1.id::bigint)
p1.id::bigint as id
, p1.inscription_id as inscription_id
, p1.block_height as block_height
, p1.txid
from last_ids p1
left outer join unwraps as p2 on p1.id = p2.id
where p2.id is null
and p1.id is not null
order by p1.id::bigint desc
, block_height desc
, microblock_sequence desc
, tx_index desc
, event_index desc;

CREATE UNIQUE INDEX inscribed_names_id_idx on inscribed_names (id);

CREATE INDEX inscribed_names_inscription_id_idx on inscribed_names (inscription_id);
21 changes: 16 additions & 5 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ model InscriptionZonefiles {
}

view Name {
id BigInt @id @unique
name String
namespace String
NameOwnership NameOwnership[]
PrimaryName PrimaryName[]
id BigInt @id @unique
name String
namespace String
NameOwnership NameOwnership[]
PrimaryName PrimaryName[]
InscribedNames InscribedNames?

@@unique([name, namespace])
@@map("names")
Expand All @@ -78,6 +79,16 @@ view NameOwnership {
@@map("name_ownership")
}

view InscribedNames {
id BigInt @id @unique
inscription_id String
name Name? @relation(fields: [id], references: [id])
blockHeight Int @map("block_height")
txid Bytes

@@map("inscribed_names")
}

// OLD:

// model Name {
Expand Down
12 changes: 8 additions & 4 deletions api/scripts/inscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ const _larry =
'$ORIGIN larry.btc.\n$TTL 3600\n_redirect\tIN\tURI\t10\t1\t"https://larrysalibra.com/"\n\n@\tIN\tA\t161.35.228.61\n\n_._nostr\tIN\tTXT\t"8a9cf8235533cf755be661170eed18e6a2006ec76a88c3fd7d21e6c13bb7b69d"\n\n';

async function run() {
const inscription = await fetchInscription(id);
console.log(inscription);
const inscription = await fetchInscription(
'ff450cf1c81ecda5a4edc1da9eb555a51469c0e3bb65449eb908ea98e21c83e5i0'
);
console.log('inscription', inscription);
// const inscription = awaitt fetchInscription(id);
// console.log(inscription);

const zonefileInfo = await verifyInscriptionZonefile(inscription.content);
console.log('zonefileInfo', zonefileInfo);
// const zonefileInfo = await verifyInscriptionZonefile(inscription.content);
// console.log('zonefileInfo', zonefileInfo);

// console.log(parseZoneFile(_zonefileTrue));
// console.log(parseZoneFile(_larry));
Expand Down
11 changes: 11 additions & 0 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { namesRoutes } from '@routes/names-routes';
import { txRoutes } from '@routes/tx-routes';
// import { trpcOpenApiRouter } from '@routes/trpc-openapi';
import { getFastifyPlugin } from 'trpc-playground/handlers/fastify';
import { fastifySchedule } from '@fastify/schedule';
import { getDeployerAddress, isDeployerEnabled } from '~/deployer';
import { makeDeployerJob } from '~/deployer/jobs';

const options: FastifyServerOptions = {
logger,
Expand Down Expand Up @@ -123,5 +126,13 @@ export async function makeApp({
return res.send({ success: true });
});

if (isDeployerEnabled() && app.stacksPrisma) {
logger.info({ deployer: getDeployerAddress() }, 'Deployer enabled, adding deployer job');
await app.register(fastifySchedule);
app.scheduler.addIntervalJob(makeDeployerJob(app.stacksPrisma));
} else {
logger.info('Deployer disabled');
}

return app;
}
10 changes: 9 additions & 1 deletion api/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DEPLOYMENT_NETWORKS } from '@clarigen/core';
import type { StacksNetwork } from 'micro-stacks/network';
import { StacksMainnet, StacksMocknet, StacksTestnet } from 'micro-stacks/network';
import { BnsContractsClient } from '@bns-x/client';

type NetworkKey = (typeof DEPLOYMENT_NETWORKS)[number];
export function getNetworkKey(): NetworkKey {
Expand All @@ -19,7 +20,9 @@ export function getNetwork(): StacksNetwork {
const netConfig = upstream ? { url: upstream } : undefined;
switch (networkKey) {
case 'devnet':
return new StacksMocknet(netConfig);
return new StacksMocknet({
url: 'http://127.0.0.1:3999',
});
case 'testnet':
return new StacksTestnet(netConfig);
case 'mainnet':
Expand All @@ -32,3 +35,8 @@ export function getNetwork(): StacksNetwork {
export function getNodeUrl() {
return getNetwork().getCoreApiUrl();
}

export function getContractsClient() {
const networkKey = getNetworkKey();
return new BnsContractsClient(networkKey);
}
29 changes: 12 additions & 17 deletions api/src/db/bns-core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { StacksDb } from '@db';
import { deserializeTuple } from '@fetchers/stacks-db';
import { getNetwork } from '~/constants';
import { convertNameBuff } from '~/contracts/utils';
import { DbQueryTag, dbQuerySummary, observeQuery } from '~/metrics';

export function getBnsSmartContractId(): string {
Expand All @@ -11,27 +13,20 @@ export function getBnsSmartContractId(): string {

export async function fetchNameByAddressCore(db: StacksDb, address: string) {
const done = observeQuery(DbQueryTag.NAME_BY_ADDRESS);
const names = await db.names.findFirst({
select: {
name: true,
},
const nameNft = await db.nftCustody.findFirst({
where: {
address,
status: {
not: 'name-revoke',
},
canonical: true,
microblock_canonical: true,
recipient: address,
assetIdentifier: getBnsSmartContractId(),
},
orderBy: [
{ registered_at: 'desc' },
{ microblock_sequence: 'desc' },
{ tx_index: 'desc' },
{ event_index: 'desc' },
],
});
done();
return names?.name ?? null;
if (nameNft === null) return null;
const nameData = deserializeTuple<{
name: string;
namespace: string;
}>(nameNft);
const name = convertNameBuff(nameData);
return name.combined;
}

export async function fetchSubdomainsByAddress(db: StacksDb, address: string) {
Expand Down
3 changes: 2 additions & 1 deletion api/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export async function refreshMaterializedViews(db: BnsDb) {
await db.$executeRaw`REFRESH MATERIALIZED VIEW CONCURRENTLY names`;
await db.$executeRaw`REFRESH MATERIALIZED VIEW CONCURRENTLY primary_names`;
await db.$executeRaw`REFRESH MATERIALIZED VIEW CONCURRENTLY name_ownership`;
await db.$executeRaw`REFRESH MATERIALIZED VIEW CONCURRENTLY inscribed_names`;
} catch (error) {
logger.error({
error,
err: error,
topic: 'refresh-materialized-views',
});
}
Expand Down
Loading
Loading