Accept Assignment
This function creates a transaction for course creators to accept and approve student assignments, transferring the assignment from the assignment validator to the course state.
acceptAssignmentTx(params)
Builds a transaction that allows a course creator to accept a student’s assignment submission and issue a module token as proof of completion.
Signature
export async function acceptAssignmentTx({
client,
provider,
approverAlias,
studentAlias,
courseId,
moduleTokenName
}: {
client: UtxorpcClient;
provider: Provider;
approverAlias: string;
studentAlias: string;
courseId: string;
moduleTokenName: string;
}): Promise<string>
Parameters
Name | Type | Description |
---|---|---|
client | UtxorpcClient | UTXO RPC client for blockchain interactions |
provider | Provider | Provider instance for accessing core functionality |
approverAlias | string | Alias of the course creator approving the assignment |
studentAlias | string | Alias of the student whose assignment is being approved |
courseId | string | Unique identifier of the course |
moduleTokenName | string | Name of the module token to be issued upon acceptance |
Returns
A promise that resolves to a string containing the transaction CBOR that can be signed and submitted.
Transaction Structure
The function constructs a complex transaction with the following components:
Inputs
-
Assignment State UTXO:
- Spends from the assignment validator using Plutus V3 script
- Uses inline datum and reference script
- Redeemer:
conStr1([])
(acceptance action)
-
Instance Governance UTXO:
- Spends from instance governance validator using Plutus V3 script
- Uses inline datum with hardcoded reference script
- Redeemer:
conStr0([builtinByteString("323232" + approverAlias)])
-
User Access Token UTXO:
- Spends the approver’s access token for authorization
- Simple UTXO input (no script)
Outputs
-
Course State Output:
- Sends course state token to course state address
- Token:
courseStateTokenPolicy + studentAlias
- Datum: Updated course state datum with module token name
-
Instance Governance Return:
- Returns governance token to instance governance address
- Preserves original governance datum
-
User Access Token Return:
- Returns access token to approver’s address
- Token:
accessTokenPolicyId + "323232" + approverAlias
Behavior
- Setup: Initializes Maestro provider and MeshTxBuilder with Preprod network configuration
- Token Resolution: Resolves course state token policy and addresses
- UTXO Collection: Gathers required UTXOs:
- User UTXOs (including access token and collateral)
- Instance governance UTXO for the course
- Assignment state UTXO for the student
- Assignment validator reference script
- Datum Validation: Validates the course state datum from assignment state
- Transaction Building: Constructs the transaction with proper inputs, outputs, and scripts
- Completion: Builds and returns the transaction CBOR
Script References
- Assignment Validator: Retrieved dynamically from instance UTXOs
- Instance Governance: Uses hardcoded reference (
4df3ebc0592b39124c5cc3a1cf680a5d7ac393531dd308e34ee499fbad7257e7
, index 3)
Errors
Throws errors if:
- User access token UTXO not found for the approver alias
- Invalid course state datum in assignment state
- Required UTXOs are missing or inaccessible
- Transaction building fails
Example Usage
Basic Assignment Acceptance
import { acceptAssignmentTx } from './accept-assignment';
// Accept a student's assignment
const txCbor = await acceptAssignmentTx({
client: utxorpcClient,
provider: sdkProvider,
approverAlias: "instructor_alice",
studentAlias: "student_bob",
courseId: "blockchain-fundamentals-2024",
moduleTokenName: "Module1Complete"
});
// Sign and submit the transaction
const signedTx = await wallet.signTx(txCbor);
const txHash = await wallet.submitTx(signedTx);
console.log(`Assignment accepted! Transaction: ${txHash}`);
Integration with Course Management
// Course creator workflow
async function approveAssignment(courseId: string, studentAlias: string, moduleToken: string) {
try {
// Build acceptance transaction
const txCbor = await acceptAssignmentTx({
client,
provider,
approverAlias: "course_creator",
studentAlias,
courseId,
moduleTokenName: moduleToken
});
// Process transaction
const result = await processTransaction(txCbor);
return {
success: true,
txHash: result.txHash,
moduleToken
};
} catch (error) {
console.error("Failed to accept assignment:", error);
return { success: false, error: error.message };
}
}
Batch Assignment Processing
// Accept multiple assignments
async function batchAcceptAssignments(assignments: Array<{
studentAlias: string;
courseId: string;
moduleTokenName: string;
}>) {
const results = [];
for (const assignment of assignments) {
const txCbor = await acceptAssignmentTx({
client,
provider,
approverAlias: "batch_approver",
...assignment
});
results.push({
student: assignment.studentAlias,
txCbor,
module: assignment.moduleTokenName
});
}
return results;
}
Workflow Integration
Assignment Lifecycle
- Student Submission: Student commits assignment using
commitAssignmentTx
- Review Period: Assignment sits in assignment validator awaiting approval
- Acceptance: Course creator uses
acceptAssignmentTx
to approve - Token Issuance: Module token is created and assigned to student
- State Update: Course state reflects completed module
Authorization Model
- Approver Verification: Uses access token to verify approver authority
- Course Association: Validates approver has rights to the specific course
- Student Validation: Ensures assignment exists for the specified student
Technical Notes
Network Configuration
- Hardcoded Network: Currently configured for Preprod testnet
- Maestro Integration: Uses Maestro as the primary provider for transaction operations
- API Key: Contains hardcoded Maestro API key (should be externalized)
Token Naming Convention
- Access Tokens: Format
policyId + "323232" + hexEncodedAlias
- Course State Tokens: Format
courseStatePolicy + hexEncodedStudentAlias
- Module Tokens: Custom names provided by course creators
Security Considerations
- Script Validation: Uses Plutus V3 scripts for secure state transitions
- Datum Integrity: Validates course state datum before processing
- Access Control: Requires valid access token for transaction authorization
- Collateral Management: Automatically selects appropriate collateral UTXO
Performance Optimization
- Reference Scripts: Uses reference scripts to reduce transaction size
- Inline Datums: Employs inline datums for efficient data storage
- UTXO Selection: Automatically selects optimal UTXOs for transaction construction
Last updated on