无法评估事务:TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型或者 Buffer 或 URL 的实例
我想查询超级账本结构区块链上的资产。我为它定义了一个函数queryCar。汽车是区块链上的一种资产,具有四/五种不同的属性,例如 模型、颜色等(我直接从 Fabric 示例 GitHub 存储库复制了链码)我使用 Fabric-network 和 Fabric-ca-client 进行构建我的 Node.js 中的 SDK。我收到此错误:
Failed to evaluate transaction: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received null
querycar Node js API 的 API 时,这是响应
{
"result": "The \"path\" argument must be of type string or an instance of Buffer or URL. Received null",
"error": null,
"errorData": null
}
当我调用查询功能的
app.get('/channels/:channelName/chaincodes/:chaincodeName', async function (req, res) {
try {
logger.debug('==================== QUERY BY CHAINCODE ==================');
var channelName = req.params.channelName;
var chaincodeName = req.params.chaincodeName;
console.log(`chaincode name is :${chaincodeName}`)
let args = req.query.args;
let fcn = req.query.fcn;
let peer = req.query.peer;
if (!chaincodeName) {
res.json(getErrorMessage('\'chaincodeName\''));
return;
}
if (!channelName) {
res.json(getErrorMessage('\'channelName\''));
return;
}
if (!fcn) {
res.json(getErrorMessage('\'fcn\''));
return;
}
if (!args) {
res.json(getErrorMessage('\'args\''));
return;
}
console.log('args==========', args);
args = args.replace(/'/g, '"');
args = JSON.parse(args);
logger.debug(args);
let message = await query.query(channelName, chaincodeName, args, fcn, req.username, req.orgname);
const response_payload = {
result: message,
error: null,
errorData: null
}
res.send(response_payload);
} catch (error) {
const response_payload = {
result: null,
error: error.name,
errorData: error.message
}
res.send(response_payload)
}
});
:助手查询区块链功能
const query = async (channelName, chaincodeName, args, fcn, username, org_name) => {
try {
const ccp = await helper.getCCP(org_name) //JSON.parse(ccpJSON);
// Create a new file system based wallet for managing identities.
const walletPath = await helper.getWalletPath(org_name) //.join(process.cwd(), 'wallet');
const wallet = await Wallets.newFileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);
// Check to see if we've already enrolled the user.
let identity = await wallet.get(username);
if (!identity) {
console.log(`An identity for the user ${username} does not exist in the wallet, so registering user`);
await helper.getRegisteredUser(username, org_name, true)
identity = await wallet.get(username);
console.log('Run the registerUser.js application before retrying');
return;
}
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccp, {
wallet, identity: username, discovery: { enabled: true, asLocalhost: true }
});
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork(channelName);
// Get the contract from the network.
const contract = network.getContract(chaincodeName);
let result;
switch (fcn) {
case "queryCar":
console.log("=============")
result = await contract.evaluateTransaction('SmartContract:'+fcn, args[0]);
break;
case "GetHistoryForAsset":
case "GetCarById":
console.log("=============")
result = await contract.evaluateTransaction('SmartContract:'+fcn, args[0]);
break;
default:
break;
}
console.log(result)
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
result = JSON.parse(result.toString());
return result
} catch (error) {
console.error(`Failed to evaluate transaction: ${error}`);
return error.message
}
}
I want to query an asset on hyper ledger fabric blockchain. I have defined a function queryCar for it. Car is an asset on the blockchain with four/five different properties, like
model, color, etc.(I have copied the chaincode directly from the fabric sample GitHub repo) I'm using fabric-network
along with fabric-ca-client
for building my
SDK in nodejs. I am getting this error :
Failed to evaluate transaction: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received null
and this as response when I call the API for querycar
{
"result": "The \"path\" argument must be of type string or an instance of Buffer or URL. Received null",
"error": null,
"errorData": null
}
Node js API for query function:
app.get('/channels/:channelName/chaincodes/:chaincodeName', async function (req, res) {
try {
logger.debug('==================== QUERY BY CHAINCODE ==================');
var channelName = req.params.channelName;
var chaincodeName = req.params.chaincodeName;
console.log(`chaincode name is :${chaincodeName}`)
let args = req.query.args;
let fcn = req.query.fcn;
let peer = req.query.peer;
if (!chaincodeName) {
res.json(getErrorMessage('\'chaincodeName\''));
return;
}
if (!channelName) {
res.json(getErrorMessage('\'channelName\''));
return;
}
if (!fcn) {
res.json(getErrorMessage('\'fcn\''));
return;
}
if (!args) {
res.json(getErrorMessage('\'args\''));
return;
}
console.log('args==========', args);
args = args.replace(/'/g, '"');
args = JSON.parse(args);
logger.debug(args);
let message = await query.query(channelName, chaincodeName, args, fcn, req.username, req.orgname);
const response_payload = {
result: message,
error: null,
errorData: null
}
res.send(response_payload);
} catch (error) {
const response_payload = {
result: null,
error: error.name,
errorData: error.message
}
res.send(response_payload)
}
});
Helper query blockchain function
const query = async (channelName, chaincodeName, args, fcn, username, org_name) => {
try {
const ccp = await helper.getCCP(org_name) //JSON.parse(ccpJSON);
// Create a new file system based wallet for managing identities.
const walletPath = await helper.getWalletPath(org_name) //.join(process.cwd(), 'wallet');
const wallet = await Wallets.newFileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);
// Check to see if we've already enrolled the user.
let identity = await wallet.get(username);
if (!identity) {
console.log(`An identity for the user ${username} does not exist in the wallet, so registering user`);
await helper.getRegisteredUser(username, org_name, true)
identity = await wallet.get(username);
console.log('Run the registerUser.js application before retrying');
return;
}
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccp, {
wallet, identity: username, discovery: { enabled: true, asLocalhost: true }
});
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork(channelName);
// Get the contract from the network.
const contract = network.getContract(chaincodeName);
let result;
switch (fcn) {
case "queryCar":
console.log("=============")
result = await contract.evaluateTransaction('SmartContract:'+fcn, args[0]);
break;
case "GetHistoryForAsset":
case "GetCarById":
console.log("=============")
result = await contract.evaluateTransaction('SmartContract:'+fcn, args[0]);
break;
default:
break;
}
console.log(result)
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
result = JSON.parse(result.toString());
return result
} catch (error) {
console.error(`Failed to evaluate transaction: ${error}`);
return error.message
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是由于将
req.org_name
传递给 Node js API 函数中的query.query
函数所致。可能的原因是由于名称不匹配作为请求发送的 json 值以及您收到的内容。
https://github.com/adhavpavan/FabricNetwork-2。 x/api-2.0 是可能使用的 GitHub 存储库。
路径参数错误来自上述存储库的
helper.js
文件中的getCCP(org)
。检查传递的 org 参数在函数内是否有效。
This is likely due to the
req.org_name
passed toquery.query
function in Node js API function.Possible reason is due to name mismatch from the json value sent as request and what you received.
https://github.com/adhavpavan/FabricNetwork-2.x/api-2.0 is the possible GitHub repository that was used.
The path argument error comes from
getCCP(org)
in thehelper.js
file from the above repo.check if the
org
argument that is passed is valid or not inside the function.