从数据库中获取实时数据
Get live data from database in solidity
我有一份 solidity 的代币合约。我想制作映射 isWhitelisted[msg.sender]
,我想我应该使用
为此。当个人钱包在 sql 数据库 上列出时,isWhitelisted
return 怎么可能 只有 ?
据我所知你不能这样检查。 (到目前为止)
但我自己使用的解决方法是将映射与结构一起使用。
struct testStruct {
string test;
bool isValue;
}
mapping (address => testStruct ) public tests;
// Than you can do
function isWhitelisted() public view returns (bool isValue_)
{
if (tests[msg.sender].isValue) {
uniName_ = tests[msg.sender].isValue;
}
}
// or use it like this
require(tests[msg.sender].isValue);
bool isValue 仅在检查 msg.sender 是否在映射中可用时才需要。如果您提供更多关于您到目前为止所做的事情的信息,我可以更好地帮助您。
更新
DieselPrice.sol,简单XML API端点:https://www.fueleconomy.gov/ws/rest/fuelprices
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
newDieselPrice(result);
DieselPriceUSD = parseInt(result, 2); // let's save it as $ cents
// do something with the USD Diesel price
}
function update() payable {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query("URL", "xml(https://www.fueleconomy.gov/ws/rest/fuelprices).fuelPrices.diesel");
}
在 __callback 中,XML 元素 "fuelPrices.diesel" 将保存到 public DieselPriceUSD 变量中。新示例:
function __callback(bytes32 myid, bool isWhitelisted ) { // I dont know if type casting is possible this way
if (msg.sender != oraclize_cbAddress()) throw;
if (isWhitelisted) {
callEventXYZ();
}
}
function checkWhitelist() payable {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query("URL", "xml(https://YourXMLAPIEndpoint?msgaddress=" + msg.sender +").isWhitelisted.value"); // Or something similar to this
}
要将 msg.sender 地址连接到查询 url 中,您可以查看此 link:
http://docs.oraclize.it/#ethereum-quick-start
例子:
strConcat()
// Absolute time: get the result from the given datasource at the specified UTC timestamp in the future
oraclize_query(scheduled_arrivaltime+3*3600,
"WolframAlpha", strConcat("flight ", flight_number, " landed"));
OR Post msg.sender 作为 JSON 到 API:
// The URL datasource also supports a supplement argument, useful for creating HTTP POST requests.
// If that argument is a valid JSON string, it will be automatically sent as JSON.
oraclize_query("URL", "json(https://shapeshift.io/sendamount).success.deposit",
'{"pair":"eth_btc","amount":"1","withdrawal":"1AAcCo21EUc1jbocjssSQDzLna9Vem2UN5"}')
我有一份 solidity 的代币合约。我想制作映射 isWhitelisted[msg.sender]
,我想我应该使用
为此。当个人钱包在 sql 数据库 上列出时,isWhitelisted
return 怎么可能 只有 ?
据我所知你不能这样检查。 (到目前为止)
但我自己使用的解决方法是将映射与结构一起使用。
struct testStruct {
string test;
bool isValue;
}
mapping (address => testStruct ) public tests;
// Than you can do
function isWhitelisted() public view returns (bool isValue_)
{
if (tests[msg.sender].isValue) {
uniName_ = tests[msg.sender].isValue;
}
}
// or use it like this
require(tests[msg.sender].isValue);
bool isValue 仅在检查 msg.sender 是否在映射中可用时才需要。如果您提供更多关于您到目前为止所做的事情的信息,我可以更好地帮助您。
更新
DieselPrice.sol,简单XML API端点:https://www.fueleconomy.gov/ws/rest/fuelprices
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
newDieselPrice(result);
DieselPriceUSD = parseInt(result, 2); // let's save it as $ cents
// do something with the USD Diesel price
}
function update() payable {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query("URL", "xml(https://www.fueleconomy.gov/ws/rest/fuelprices).fuelPrices.diesel");
}
在 __callback 中,XML 元素 "fuelPrices.diesel" 将保存到 public DieselPriceUSD 变量中。新示例:
function __callback(bytes32 myid, bool isWhitelisted ) { // I dont know if type casting is possible this way
if (msg.sender != oraclize_cbAddress()) throw;
if (isWhitelisted) {
callEventXYZ();
}
}
function checkWhitelist() payable {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query("URL", "xml(https://YourXMLAPIEndpoint?msgaddress=" + msg.sender +").isWhitelisted.value"); // Or something similar to this
}
要将 msg.sender 地址连接到查询 url 中,您可以查看此 link: http://docs.oraclize.it/#ethereum-quick-start
例子: strConcat()
// Absolute time: get the result from the given datasource at the specified UTC timestamp in the future
oraclize_query(scheduled_arrivaltime+3*3600,
"WolframAlpha", strConcat("flight ", flight_number, " landed"));
OR Post msg.sender 作为 JSON 到 API:
// The URL datasource also supports a supplement argument, useful for creating HTTP POST requests.
// If that argument is a valid JSON string, it will be automatically sent as JSON.
oraclize_query("URL", "json(https://shapeshift.io/sendamount).success.deposit",
'{"pair":"eth_btc","amount":"1","withdrawal":"1AAcCo21EUc1jbocjssSQDzLna9Vem2UN5"}')