-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea3e489
commit b39e9aa
Showing
6 changed files
with
62 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getProviderOrThrow } from 'src/provider'; | ||
import { CreateInscriptionOptions, CreateRepeatInscriptionsOptions } from './types'; | ||
import { Json, createUnsecuredToken } from 'jsontokens'; | ||
import { validateInscriptionPayload } from './utils'; | ||
|
||
export const createRepeatInscriptions = async (options: CreateRepeatInscriptionsOptions) => { | ||
const { getProvider } = options; | ||
const provider = await getProviderOrThrow(getProvider); | ||
|
||
validateInscriptionPayload(options.payload); | ||
|
||
try { | ||
const request = createUnsecuredToken(options.payload as unknown as Json); | ||
const response = await provider.createInscription(request); | ||
options.onFinish?.(response); | ||
} catch (error) { | ||
console.error('[Connect] Error during create repeat inscriptions', error); | ||
options.onCancel?.(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { CreateInscriptionPayload } from './types'; | ||
|
||
const MAX_CONTENT_LENGTH_MAINNET = 400e3; // 400kb is the max miners will mine | ||
const MAX_CONTENT_LENGTH_TESTNET = 60e3; // 60kb limit on Testnet to prevent spam | ||
|
||
export const validateInscriptionPayload = (payload: CreateInscriptionPayload) => { | ||
const { contentType, content, payloadType, network, appFeeAddress, appFee } = payload; | ||
if (!/^[a-z]+\/[a-z0-9\-\.\+]+(?=;.*|$)/.test(contentType)) { | ||
throw new Error('Invalid content type detected'); | ||
} | ||
|
||
if (!content || content.length === 0) { | ||
throw new Error('Empty content not allowed'); | ||
} | ||
|
||
if (!payloadType || (payloadType !== 'BASE_64' && payloadType !== 'PLAIN_TEXT')) { | ||
throw new Error('Empty invalid payloadType specified'); | ||
} | ||
|
||
if ( | ||
content.length > | ||
(network.type === 'Mainnet' ? MAX_CONTENT_LENGTH_MAINNET : MAX_CONTENT_LENGTH_TESTNET) | ||
) { | ||
throw new Error('Content too large'); | ||
} | ||
|
||
if ((appFeeAddress?.length ?? 0) > 0 && (appFee ?? 0) <= 0) { | ||
throw new Error('Invalid combination of app fee address and fee provided'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters