Commit 3915b167 authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'NFT-endpoint-changes-2' into 'master'

Nft endpoint changes 2

See merge request !27
parents 8100d282 6f793922
const MongoClient = require("mongodb").MongoClient;
async function GetIssuerPair(publicKey, collectionName) {
const uri = process.env.DATABASE_URL;
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
try {
await client.connect();
const collection = client.db().collection(collectionName);
const result = await collection.findOne({ publickey: publicKey });
if (!result) {
throw new Error("No record found for the provided public key");
}
return {
issuerKey: result.issuerpk,
issuerSeed: result.issuersk,
};
} finally {
await client.close();
}
}
module.exports = GetIssuerPair;
const StellarSdk = require("stellar-sdk");
require("dotenv").config();
const server = new StellarSdk.Server(process.env.STELLARTESTNET);
async function DoManageData(sourceSeed, assetCode, ipfsHash) {
try {
// Load source account details
const sourceKeypair = StellarSdk.Keypair.fromSecret(sourceSeed);
const account = await server.loadAccount(sourceKeypair.publicKey());
// Create a manage data operation with assetCode as name and ipfsHash as value
const operation = StellarSdk.Operation.manageData({
name: assetCode,
value: ipfsHash,
});
// Build the transaction
const transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
})
.addOperation(operation)
.setTimeout(30)
.build();
// Sign the transaction with the source account keypair
transaction.sign(sourceKeypair);
// Submit the transaction to the Stellar network
const transactionResult = await server.submitTransaction(transaction);
// Log the transaction hash
console.log(
`Transaction hash for NFT issuer manage data : ${transactionResult.hash}`
);
return true;
} catch (error) {
console.error("Error when submitting NFT manage data", error);
return false;
}
}
module.exports = DoManageData;
const StellarSdk = require("stellar-sdk");
require("dotenv").config();
const server = new StellarSdk.Server(process.env.STELLARTESTNET);
async function SendPayment(
assetCode,
sourceSeed,
destinationPublicKey,
issuerPk
) {
try {
// Load source account details
const sourceKeypair = StellarSdk.Keypair.fromSecret(sourceSeed);
const sourceAccount = await server.loadAccount(sourceKeypair.publicKey());
// Load destination account details
const destinationAccount = await server.loadAccount(destinationPublicKey);
// Create the payment operation
const paymentOperation = StellarSdk.Operation.payment({
destination: destinationPublicKey,
asset: new StellarSdk.Asset(assetCode, issuerPk),
amount: "0.0000001",
});
// Build the transaction
const transaction = new StellarSdk.TransactionBuilder(sourceAccount, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
})
.addOperation(paymentOperation)
.setTimeout(30)
.build();
// Sign the transaction with the source account keypair
transaction.sign(sourceKeypair);
// Submit the transaction to the Stellar network
const transactionResult = await server.submitTransaction(transaction);
// Log the transaction hash
console.log(`Transaction hash for payment : ${transactionResult.hash}`);
return true;
} catch (error) {
console.error(error);
return false;
}
}
module.exports = SendPayment;
......@@ -17,7 +17,7 @@ async function CreateTrustline(assetCode, issuerKey, sourceAccountSeed) {
.addOperation(
StellarSdk.Operation.changeTrust({
asset: new StellarSdk.Asset(assetCode, issuerKey),
limit: "1",
limit: "0.0000001",
})
)
.setTimeout(30)
......
const NFTRequest = require("./../model/stellar/nftRequests"); // assuming "nftRequest" is the name of the Mongoose model
async function UpdateNFTRequestStatus(assetcode) {
try {
const filter = { assetcode: assetcode };
const update = { status: "Completed" };
const options = { new: true }; // Return the updated document
const updatedRequest = await NFTRequest.findOneAndUpdate(
filter,
update,
options
);
return !!updatedRequest; // convert updatedRequest to boolean value
} catch (error) {
console.error(error);
return false;
}
}
module.exports = UpdateNFTRequestStatus;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment