Method for invoking transaction from another transaction in Hyperledge composer - hyperledger

The old version of hyperledger support below method. But newest not
const generateReport = getFactory().newTransaction('org.cusat.hospital', 'GenerateReport');
While testing in new version shows an error of
Error: No valid responses from any peers. Response from attempted peer comms was an error: Error: transaction returned with failure: TypeError: getFactory(...).newTransaction is not a function
Please suggest alternative method.

i found one way of invoking transaction from java script. see if this helps.
const TransactionSubmit = require('composer-cli').Transaction.Submit;
let options = {
card: 'admin#tutorial-network',
data: '{"$class":"net.biz.digitalPropertyNetwork.RegisterPropertyForSale","transactionId":"TRANSACTION_001","seller":"mae#biznet.org","title":"TITLE_001"}'
};
TransactionSubmit.handler(options);

Related

Google reCAPTCHA Enterprise Unknown field error when Create Assessment

I did follow their documentation on https://googleapis.dev/ruby/google-cloud-recaptcha_enterprise-v1/latest/index.html
I first added the env variable RECAPTCHA_ENTERPRISE_CREDENTIALS then run the
client = ::Google::Cloud::RecaptchaEnterprise::V1::RecaptchaEnterpriseService::Client.new
documentation says response = client.create_assessment request but documentation didn't add sample request so I did assume that it will look like in this documentation https://cloud.google.com/recaptcha-enterprise/docs/create-assessment
{
"event": {
"token": "token",
"siteKey": "key"
}
}
But when I execute the client.create_assessment it is giving me error ArgumentError: Unknown field name 'event' in initialization map entry.
I also tried to follow this https://googleapis.dev/ruby/google-cloud-recaptcha_enterprise-v1/latest/Google/Cloud/RecaptchaEnterprise/V1/RecaptchaEnterpriseService/Client.html#create_assessment-instance_method
where the parameters is request and also gives me error ArgumentError: Unknown field name 'request' in initialization map entry.
What could be the correct parameter/request for creating assessment?
Gem I used is google-cloud-recaptcha_enterprise-v1 and google-cloud-recaptcha_enterprise
So I solve this issue by using client.create_assessment(parent: "projects/{your project-id}", assessment: event) my event value was event = Google::Cloud::RecaptchaEnterprise::V1::Event.new(token: "token from execute", site_key: "your site key")
It solves the error and answers the question (but another error after this one occurred about permission denied). I Will update once resolved.

Azure IoT Device: Type error in client.js

I try to get an ARM device connected to Azure IoT Hub. I chose Node.js and got some sample code to get the device connected. I added the required NPM packages such as azure_iot_device, azure_iot_common, azure_iot_http_base.
Within the code, there is one line of code which causes an error.
The line: client.sendEvent(message, printResultFor('send'));
After this, on the debugging console I get the message:
\NodejsWebApp1\node_modules\azure-iot-device\lib\client.js:596
return new Client(new transportCtor(authenticationProvider), null, new blob_upload_1.BlobUploadClient(authenticationProvider));
^
TypeError: transportCtor is not a function
at Function.Client.fromConnectionString
(C:\Users\InterestedGuy\source\repos\NodejsWebApp1\NodejsWebApp1\node_modules\azure-iot-device\lib\client.js:596:27)
at sendmsg (C:\Users\InterestedGuy\source\repos\NodejsWebApp1\NodejsWebApp1\server.js:123:32)
at Server. (C:\Users\InterestedGuy\source\repos\NodejsWebApp1\NodejsWebApp1\server.js:48:9)
at emitTwo (events.js:87:13)
at Server.emit (events.js:172:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:529:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
Press any key to continue...
First guess was that I miss a library so I simply searched the Web where transportCtor should have been defined - but no success.
So the easy question is: where should this function be defined? I would expect the function is part of the Azure IoT SDK but I could not find it. Since the module client.js from azure_iot_device is reporting the error I expect it somewhere within the SDK - but where?
THX for any advice
You should install azure-iot-device-http package to communicate with Azure IoT Hub from any device over HTTP 1.1. You can use this command to get the latest version.
npm install -g azure-iot-device-http#latest
Following code is a tutorial shows how to use this package.
var clientFromConnectionString = require('azure-iot-device-http').clientFromConnectionString;
var Message = require('azure-iot-device').Message;
var connectionString = '[IoT Hub device connection string]';
var client = clientFromConnectionString(connectionString);
var connectCallback = function (err) {
if (err) {
console.error('Could not connect: ' + err);
} else {
console.log('Client connected');
var message = new Message('some data from my device');
client.sendEvent(message, function (err) {
if (err) console.log(err.toString());
});
client.on('message', function (msg) {
console.log(msg);
client.complete(msg, function () {
console.log('completed');
});
});
}
};
client.open(connectCallback);
BTW,for this tutorial you also need to install azure-iot-device package.

Hyperledger composer calling external REST API

I am a developer with hyperledger composer. I try to use Calling an HTTP or REST API from Transaction Processor Functions with method POST and request body but I have error status code 500. I want to use method POST with request body to my server.
My code:
async function testStocks(transaction) {
const participant = getCurrentParticipant();
const json = '{"name:tester"}';//my request body
await request.post({ uri: 'http://www...', json });
// Update the current participant in the participant registry.
const participantRegistry = await getParticipantRegistry('org.example.Trader');
await participantRegistry.update(participant);
}
My error:
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: StatusCodeError: 400 - undefined",
"stack": "Error: Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: StatusCodeError: 400 - undefined\n at _initializeChannel.then.then.then.then.catch (/home/pc/.nvm/versions/node/v8.10.0/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:965:34)\n at <anonymous>"
}
}
participant variable is undefined in await participantRegistry.update(participant);.
You are missing code from the example # https://hyperledger.github.io/composer/latest/integrating/call-out.
// Get the current participant, and update their stock and balance.
const participant = getCurrentParticipant();
// update participant here... <<--------------------
// Update the current participant in the participant registry.
const participantRegistry = await getParticipantRegistry('org.example.Trader');
await participantRegistry.update(participant);

Trying to sync a dataset in Amazon Cognito returns CognitoSyncError

let dataset: AWSCognitoDataset = self.syncClient.openOrCreateDataset(name)
dataset.synchronize()
AWSiOSSDKv2 [Error] AWSCognitoDataset.m line:503 | __30-[AWSCognitoDataset syncPush:]_block_invoke | An error occured attempting to update records: Error Domain=com.amazonaws.AWSCognitoSyncErrorDomain Code=8 "Lambda function returned an invalid output. Please check your JSON structure." UserInfo={NSLocalizedDescription=Lambda function returned an invalid output. Please check your JSON structure., NSLocalizedFailureReason=InvalidLambdaFunctionOutputException:}
The error occurs for a specific dataset every time. The dataset JSON is valid. Any idea why is this happening? How can I get more info on the error?
The error here indicates that your Sync trigger Lambda function is not returning the service contract output in expected format.
Sync triggers follow the service provider interface programming paradigm. Cognito will provide input in a specific JSON format to your Lambda function and it expects the return value to be the same format.
The developer guide has the format documented with an example lambda function.

Create New Row in database using Odata

I have an OData Service that is pointing to a table in the database. I want to enter a new record in the table based on the details from user.
I am using the .create method, but the data doesn't seem to get entered in table.
oView=this.getView();
var df = {};
var name = oView.byId("__input3").getValue();
var goal = oView.byId("__area0").getValue();
df.NAME = name;
df.GOAL = goal;
df.TYPE = "type";
df.THEME = "Theme";
var oModel1= new sap.ui.model.odata.ODataModel("/GDH_OData/services/df.xsodata/");
oModel1.create('/Df', df, null, function() {
alert("SUCCESS");
}, function() {
alert("FAIL");
});
Please help where I am going wrong
you're not giving a lot of info, here...
what is the result of your create call ? SUCCESS or FAIL ? if the later, what is the error message returned ? the following error function can help you on this
function(error) {
var message = $(error.response.body).find('message').first().text();
console.log(message);
alert(message);
}
Is the creation code in the backend called (if you put an external breakpoint in your service, do you get the debugger ?) if so, what is the result of debugging step-by-step ?
edit
if there is a "forbidden" response, then you should check the result of transaction su53 for the user. You'll probably have a failed autorization. Then it's just adding the service to your role autorisation.
PS : its better to add your answer to my questions(s) in your question, under a "edit" or "more information" than to put it as another answer. Thus there is only one place to check for the whole problem.
regards
The result is Fail and the error is "Failed to load resource: the server responded with a status of 403 (Forbidden)"

Resources