cool
This commit is contained in:
parent
83e3857727
commit
2ecadcf19f
@ -95,8 +95,98 @@ export async function POST(request: NextRequest) {
|
||||
// Get current timestamp for the meta note
|
||||
const timestamp = new Date().toUTCString();
|
||||
|
||||
// Prepare record data
|
||||
const recordData = {
|
||||
// Step 1: Create and publish ApplicationRecord first
|
||||
console.log('Step 1: Publishing ApplicationRecord...');
|
||||
const applicationRecord = {
|
||||
type: 'ApplicationRecord',
|
||||
name: appName,
|
||||
version: '0.0.1',
|
||||
app_type: 'webapp',
|
||||
repository: [url],
|
||||
repository_ref: 'main', // Default reference or commit hash
|
||||
app_version: '0.0.1'
|
||||
};
|
||||
|
||||
// Create fee for transaction directly
|
||||
const fee = {
|
||||
amount: [{ denom: 'alnt', amount: '900000' }],
|
||||
gas: '900000',
|
||||
};
|
||||
|
||||
console.log('Application record data:', applicationRecord);
|
||||
|
||||
// Publish the application record
|
||||
let applicationRecordId;
|
||||
try {
|
||||
const appRecordResult = await registryTransactionWithRetry(() =>
|
||||
registry.setRecord(
|
||||
{
|
||||
privateKey: config.privateKey,
|
||||
record: applicationRecord,
|
||||
bondId: config.bondId,
|
||||
},
|
||||
config.privateKey,
|
||||
fee
|
||||
)
|
||||
) as { id?: string };
|
||||
|
||||
applicationRecordId = appRecordResult.id;
|
||||
console.log('Application record published with ID:', applicationRecordId);
|
||||
|
||||
if (!applicationRecordId) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
message: 'Failed to publish ApplicationRecord'
|
||||
}, { status: 500 });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error publishing ApplicationRecord:', err);
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
message: err instanceof Error ? err.message : 'Unknown error publishing ApplicationRecord'
|
||||
}, { status: 500 });
|
||||
}
|
||||
|
||||
// Step 2: Set name mappings
|
||||
console.log('Step 2: Setting name mappings...');
|
||||
try {
|
||||
// Set the main LRN to point to the application record
|
||||
await registryTransactionWithRetry(() =>
|
||||
registry.setName(
|
||||
{
|
||||
cid: applicationRecordId,
|
||||
lrn
|
||||
},
|
||||
config.privateKey,
|
||||
fee
|
||||
)
|
||||
);
|
||||
console.log(`Set name mapping: ${lrn} -> ${applicationRecordId}`);
|
||||
|
||||
// Set the versioned LRN (with repository_ref)
|
||||
await registryTransactionWithRetry(() =>
|
||||
registry.setName(
|
||||
{
|
||||
cid: applicationRecordId,
|
||||
lrn: `${lrn}@main` // Using 'main' as default ref
|
||||
},
|
||||
config.privateKey,
|
||||
fee
|
||||
)
|
||||
);
|
||||
console.log(`Set name mapping: ${lrn}@main -> ${applicationRecordId}`);
|
||||
} catch (err) {
|
||||
console.error('Error setting name mappings:', err);
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
message: err instanceof Error ? err.message : 'Unknown error setting name mappings'
|
||||
}, { status: 500 });
|
||||
}
|
||||
|
||||
// Step 3: Create ApplicationDeploymentRequest
|
||||
console.log('Step 3: Creating ApplicationDeploymentRequest...');
|
||||
// Prepare record data for deployment request
|
||||
const deploymentRequestData = {
|
||||
type: 'ApplicationDeploymentRequest',
|
||||
version: '1.0.0',
|
||||
name: appName,
|
||||
@ -111,28 +201,16 @@ export async function POST(request: NextRequest) {
|
||||
payment: txHash,
|
||||
};
|
||||
|
||||
// Create fee for transaction directly
|
||||
const fee = {
|
||||
amount: [{ denom: 'alnt', amount: '900000' }],
|
||||
gas: '900000',
|
||||
};
|
||||
console.log('Deployment request data:', deploymentRequestData);
|
||||
|
||||
console.log('Using fee:', fee);
|
||||
|
||||
console.log('Publishing record to Laconic Registry...');
|
||||
console.log('Record data:', {
|
||||
...recordData,
|
||||
payment: txHash, // Include the txHash in logs
|
||||
});
|
||||
|
||||
// Publish the record using the SDK
|
||||
let result;
|
||||
// Publish the deployment request
|
||||
let deploymentRequestId;
|
||||
try {
|
||||
result = await registryTransactionWithRetry(() =>
|
||||
const deployRequestResult = await registryTransactionWithRetry(() =>
|
||||
registry.setRecord(
|
||||
{
|
||||
privateKey: config.privateKey,
|
||||
record: recordData,
|
||||
record: deploymentRequestData,
|
||||
bondId: config.bondId,
|
||||
},
|
||||
config.privateKey,
|
||||
@ -140,26 +218,30 @@ export async function POST(request: NextRequest) {
|
||||
)
|
||||
) as { id?: string };
|
||||
|
||||
console.log('Publishing result:', result);
|
||||
deploymentRequestId = deployRequestResult.id;
|
||||
console.log('Deployment request published with ID:', deploymentRequestId);
|
||||
|
||||
if (!deploymentRequestId) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
message: 'Failed to publish ApplicationDeploymentRequest'
|
||||
}, { status: 500 });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error publishing record:', err);
|
||||
console.error('Error publishing deployment request:', err);
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
message: err instanceof Error ? err.message : 'Unknown error publishing record'
|
||||
message: err instanceof Error ? err.message : 'Unknown error publishing deployment request'
|
||||
}, { status: 500 });
|
||||
}
|
||||
|
||||
if (result && result.id) {
|
||||
return NextResponse.json({
|
||||
id: result.id,
|
||||
status: 'success',
|
||||
});
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
message: 'Failed to create record in Laconic Registry'
|
||||
}, { status: 500 });
|
||||
}
|
||||
// Return combined results
|
||||
return NextResponse.json({
|
||||
id: deploymentRequestId,
|
||||
applicationRecordId: applicationRecordId,
|
||||
status: 'success',
|
||||
lrn: lrn
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to create application deployment request:', error);
|
||||
return NextResponse.json({
|
||||
|
||||
@ -17,6 +17,8 @@ export default function Home() {
|
||||
const [status, setStatus] = useState<'idle' | 'verifying' | 'creating' | 'success' | 'error'>('idle');
|
||||
const [txHash, setTxHash] = useState<string | null>(null);
|
||||
const [recordId, setRecordId] = useState<string | null>(null);
|
||||
const [appRecordId, setAppRecordId] = useState<string | null>(null);
|
||||
const [lrn, setLrn] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const handleConnect = (address: string) => {
|
||||
@ -50,6 +52,12 @@ export default function Home() {
|
||||
|
||||
if (result.status === 'success') {
|
||||
setRecordId(result.id);
|
||||
if (result.applicationRecordId) {
|
||||
setAppRecordId(result.applicationRecordId);
|
||||
}
|
||||
if (result.lrn) {
|
||||
setLrn(result.lrn);
|
||||
}
|
||||
setStatus('success');
|
||||
} else {
|
||||
setStatus('error');
|
||||
@ -88,6 +96,8 @@ export default function Home() {
|
||||
status={status}
|
||||
txHash={txHash || undefined}
|
||||
recordId={recordId || undefined}
|
||||
appRecordId={appRecordId || undefined}
|
||||
lrn={lrn || undefined}
|
||||
error={error || undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -4,6 +4,8 @@ interface StatusDisplayProps {
|
||||
status: 'idle' | 'verifying' | 'creating' | 'success' | 'error';
|
||||
txHash?: string;
|
||||
recordId?: string;
|
||||
appRecordId?: string;
|
||||
lrn?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
@ -11,6 +13,8 @@ export default function StatusDisplay({
|
||||
status,
|
||||
txHash,
|
||||
recordId,
|
||||
appRecordId,
|
||||
lrn,
|
||||
error,
|
||||
}: StatusDisplayProps) {
|
||||
if (status === 'idle') return null;
|
||||
@ -50,12 +54,26 @@ export default function StatusDisplay({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{appRecordId && (
|
||||
<div className="mb-2">
|
||||
<p className="text-sm font-medium text-gray-700">Application Record ID:</p>
|
||||
<p className="text-sm font-mono break-all">{appRecordId}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{recordId && (
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-700">Laconic Registry Record ID:</p>
|
||||
<div className="mb-2">
|
||||
<p className="text-sm font-medium text-gray-700">Deployment Request Record ID:</p>
|
||||
<p className="text-sm font-mono break-all">{recordId}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{lrn && (
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-700">Laconic Resource Name (LRN):</p>
|
||||
<p className="text-sm font-mono break-all">{lrn}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@ -23,6 +23,8 @@ export const createApplicationDeploymentRequest = async (
|
||||
if (response.ok && result.status === 'success') {
|
||||
return {
|
||||
id: result.id,
|
||||
applicationRecordId: result.applicationRecordId,
|
||||
lrn: result.lrn,
|
||||
status: 'success',
|
||||
};
|
||||
} else {
|
||||
|
||||
@ -42,6 +42,8 @@ export interface LaconicRecordData {
|
||||
|
||||
export interface CreateRecordResponse {
|
||||
id: string;
|
||||
applicationRecordId?: string;
|
||||
lrn?: string;
|
||||
status: 'success' | 'error';
|
||||
message?: string;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user