Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFlicker committed Jul 13, 2023
1 parent 887102b commit b9320ee
Show file tree
Hide file tree
Showing 77 changed files with 7,276 additions and 566 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "ordinals",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"workspaces": [
Expand Down
8 changes: 5 additions & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
"name": "@0xflick/ordinals-backend",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"main": "src/index.ts",
"license": "MIT",
"dependencies": {
"@0xflick/mempool.js": "^2.3.0",
"@aws-sdk/client-dynamodb": "^3.359.0",
"@aws-sdk/client-s3": "^3.363.0",
"@aws-sdk/lib-dynamodb": "^3.359.0",
"bunyan": "^1.8.15"
"bunyan": "^1.8.15",
"cookie": "^0.5.0"
},
"devDependencies": {
"@types/bunyan": "^1.8.8"
"@types/bunyan": "^1.8.8",
"@types/cookie": "^0.5.1"
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/bitcoin/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export type IFeesRecommended = Awaited<
>;

export async function estimateFees(
mempool: MempoolClient
mempool: MempoolClient["bitcoin"]
): Promise<IFeesRecommended> {
const fees = await mempool.bitcoin.fees.getFeesRecommended();
const fees = await mempool.fees.getFeesRecommended();
return fees;
}
17 changes: 15 additions & 2 deletions packages/backend/src/bitcoin/inscription.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {
BitcoinNetworkNames,
InscriptionContent,
InscriptionFile,
generateFundingAddress,
generatePrivKey,
} from "@0xflick/inscriptions";
import { IInscriptionDocFundingWait } from "../../../models/src/doc";
import {
hashInscriptions,
toAddressInscriptionId,
IInscriptionDocFundingWait,
} from "@0xflick/ordinals-models";

export async function createInscriptionTransaction({
address,
Expand All @@ -18,7 +23,7 @@ export async function createInscriptionTransaction({
feeRate: number;
tip: number;
inscriptions: InscriptionContent[];
}): Promise<IInscriptionDocFundingWait> {
}): Promise<IInscriptionDocFundingWait & { files: InscriptionFile[] }> {
const privKey = generatePrivKey();
const {
amount,
Expand All @@ -31,6 +36,7 @@ export async function createInscriptionTransaction({
overhead,
padding,
totalFee,
files,
} = await generateFundingAddress({
address,
inscriptions,
Expand All @@ -41,6 +47,13 @@ export async function createInscriptionTransaction({
});

return {
id: toAddressInscriptionId(
hashInscriptions(
fundingAddress,
inscriptionsToWrite.map((i) => i.tapkey)
)
),
files,
fundingAddress,
fundingAmountBtc: amount,
initCBlock,
Expand Down
13 changes: 6 additions & 7 deletions packages/backend/src/bitcoin/mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ function urlForNetworkName(network: BitcoinNetworkNames) {
export type MempoolClient = ReturnType<typeof createMempoolClient>;
export function createMempoolClient({
network,
hostname,
protocol,
}: {
hostname: string;
protocol: "http" | "https";
network: BitcoinNetworkNames;
}) {
const url = new URL(urlForNetworkName(network));
const protocol = url.protocol.slice(0, -1);
if (["http", "https"].includes(protocol)) {
throw new Error(`Unsupported protocol: ${protocol}`);
}
return mempoolJS({
network,
hostname: url.hostname,
protocol: protocol as "http" | "https",
hostname,
protocol,
});
}
3 changes: 0 additions & 3 deletions packages/backend/src/dao/collection.ts

This file was deleted.

40 changes: 34 additions & 6 deletions packages/backend/src/dao/funding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,46 @@ import {
IAddressInscriptionModel,
TInscriptionDoc,
InscriptionFile,
InscriptionId,
TCollectionModel,
ID_Collection,
} from "@0xflick/ordinals-models";

export interface IFundingDao {
createFunding(item: IAddressInscriptionModel): Promise<void>;
getFunding(id: string): Promise<IAddressInscriptionModel>;
export interface IFundingDao<
ItemInputType extends Record<string, any> = {},
ItemMeta extends Record<string, any> = {},
ItemReturnType = any,
CollectionInputType extends Record<string, any> = {},
CollectionMeta extends Record<string, any> = {},
CollectionReturnType = any
> {
createFunding(
item: IAddressInscriptionModel<ItemInputType>
): Promise<ItemReturnType>;
getFunding(id: string): Promise<IAddressInscriptionModel<ItemMeta>>;
deleteFunding(id: string): Promise<void>;
createCollection(
item: TCollectionModel<CollectionInputType>
): Promise<CollectionReturnType>;
getCollection(id: ID_Collection): Promise<TCollectionModel<CollectionMeta>>;
deleteCollection(id: ID_Collection): Promise<void>;
incrementCollectionTotalCount(id: ID_Collection): Promise<number>;
updateMaxSupply(id: ID_Collection, maxSupply: number): Promise<void>;
updateCollectionMeta(
id: ID_Collection,
meta: CollectionMeta,
incrementTotalCount?: boolean
): Promise<Partial<TCollectionModel<CollectionMeta>>>;
}

export interface IFundingDocDao {
transactionKey(opts: { address: string; id: string; tapKey: string }): string;
transactionKey(opts: { fundingAddress: string; id: string }): string;
transactionContentKey(id: InscriptionId): string;
updateOrSaveInscriptionTransaction(item: TInscriptionDoc): Promise<void>;
saveInscriptionContent(item: InscriptionFile): Promise<void>;
getInscriptionContent(tapKey: string): Promise<InscriptionFile>;
getInscriptionTransaction(id: string): Promise<TInscriptionDoc>;
getInscriptionContent(id: InscriptionId): Promise<InscriptionFile>;
getInscriptionTransaction(opts: {
fundingAddress: string;
id: string;
}): Promise<TInscriptionDoc>;
}
3 changes: 2 additions & 1 deletion packages/backend/src/dao/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./funding.js"
export * from "./funding.js";
export * from "./ordinals/index.js";
11 changes: 11 additions & 0 deletions packages/backend/src/dao/ordinals/incrementingReveal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IOrdinalIncrementingRevealModel } from "@0xflick/ordinals-models";

export interface IIncrementingRevealMeta
extends IOrdinalIncrementingRevealModel {}
interface IIncrementingRevealReturn {
tokenId: number;
}

export interface IIncrementingRevealDao {
nextTokenId(): Promise<IIncrementingRevealReturn>;
}
1 change: 1 addition & 0 deletions packages/backend/src/dao/ordinals/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./incrementingReveal.js";
8 changes: 7 additions & 1 deletion packages/backend/src/dynamodb/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import {
awsEndpoint,
awsRegion,
dynamoDbUrl,
dynamoDbRegion,
dynamoDbSslEnabled,
} from "../utils/config.js";
Expand All @@ -11,9 +12,14 @@ let instance: DynamoDBDocumentClient;

export function createDb(opts?: DynamoDBClientConfig) {
const config = {
endpoint: awsEndpoint.get(),
endpoint: dynamoDbUrl.get() ?? awsEndpoint.get(),
region: dynamoDbRegion.get() ?? awsRegion.get(),
sslEnabled: dynamoDbSslEnabled.get(),
...(process.env.MOCK_DYNAMODB_ENDPOINT && {
endpoint: process.env.MOCK_DYNAMODB_ENDPOINT,
sslEnabled: false,
region: "local",
}),
...opts,
};
const ddb = new DynamoDBClient(config);
Expand Down
44 changes: 41 additions & 3 deletions packages/backend/src/dynamodb/factory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
import type { IFundingDao } from "../dao/funding.js";
import { tableNames } from "../utils/config.js";
import { createDb } from "./create.js";
import { FundingDao } from "./funding.js";
import {
FundingDao,
TFundingCollectionReturner,
TFundingItemReturner,
} from "./funding.js";

export function createDynamoDbFundingDao(): IFundingDao {
export function createDynamoDbFundingDao<
ItemInputType extends Record<string, any> = {},
ItemMeta extends Record<string, any> = {},
ItemReturnType = any,
CollectionInputType extends Record<string, any> = {},
CollectionMeta extends Record<string, any> = {},
CollectionReturnType = any
>({
itemFundingUpdater,
collectionFundingUpdater,
}: {
itemFundingUpdater: TFundingItemReturner<ItemInputType, ItemReturnType>;
collectionFundingUpdater: TFundingCollectionReturner<
CollectionInputType,
CollectionReturnType
>;
}): IFundingDao<
ItemInputType,
ItemMeta,
ItemReturnType,
CollectionInputType,
CollectionMeta,
CollectionReturnType
> {
const allTableNames = tableNames.get();
FundingDao.TABLE_NAME = allTableNames.funding ?? FundingDao.TABLE_NAME;
return new FundingDao(createDb());
return new FundingDao<
ItemInputType,
ItemMeta,
ItemReturnType,
CollectionInputType,
CollectionMeta,
CollectionReturnType
>({
client: createDb(),
itemFundingUpdater,
collectionFundingUpdater,
});
}
Loading

0 comments on commit b9320ee

Please sign in to comment.