javascript 的 Hyperledger Composer
Hyperledger Composer with javascript
我是 hyperledger composer 的初学者。我想从服务器检索数据,例如 AJAX,它在 hyperledger composer 的 javascript 文件中使用它。
我该如何实现?
下面是我在 hyperledger composer 的脚本文件中使用的来自 w3school 的示例。
/**
* Sample transaction processor function.
* @param {org.acme.sample.SampleTransaction} tx The sample transaction instance.
* @transaction
*/
function sampleTransaction(tx) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
您可以在 Composer 交易函数中使用 call-outs。但是请记住,对于智能合约交易,所有执行交易逻辑的节点都必须 return 一个确定性的结果——否则你的交易将无法被背书(你可能知道,只是说)
在此处查看更多详细信息和示例 -> https://hyperledger.github.io/composer/latest/integrating/call-out
function handlePost(postTransaction) {
var url = 'https://composer-node-red.mybluemix.net/compute';
// call-out
return post( url, postTransaction)
.then(function (result) {
// alert(JSON.stringify(result));
postTransaction.asset.value = 'Count is ' + result.body.sum;
// now update an Asset Registry (Composer)
return getAssetRegistry('org.example.sample.SampleAsset')
.then(function (assetRegistry) {
return assetRegistry.update(postTransaction.asset);
});
});
}
我是 hyperledger composer 的初学者。我想从服务器检索数据,例如 AJAX,它在 hyperledger composer 的 javascript 文件中使用它。
我该如何实现?
下面是我在 hyperledger composer 的脚本文件中使用的来自 w3school 的示例。
/** * Sample transaction processor function. * @param {org.acme.sample.SampleTransaction} tx The sample transaction instance. * @transaction */ function sampleTransaction(tx) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("GET", "ajax_info.txt", true); xhttp.send(); }
您可以在 Composer 交易函数中使用 call-outs。但是请记住,对于智能合约交易,所有执行交易逻辑的节点都必须 return 一个确定性的结果——否则你的交易将无法被背书(你可能知道,只是说)
在此处查看更多详细信息和示例 -> https://hyperledger.github.io/composer/latest/integrating/call-out
function handlePost(postTransaction) {
var url = 'https://composer-node-red.mybluemix.net/compute';
// call-out
return post( url, postTransaction)
.then(function (result) {
// alert(JSON.stringify(result));
postTransaction.asset.value = 'Count is ' + result.body.sum;
// now update an Asset Registry (Composer)
return getAssetRegistry('org.example.sample.SampleAsset')
.then(function (assetRegistry) {
return assetRegistry.update(postTransaction.asset);
});
});
}