从数据库中获取实时数据

时间:2018-03-25 21:49:53

标签: sql reactjs create-react-app solidity

我有一份坚实的代币合约。我想制作映射isWhitelisted[msg.sender],我想我应该使用

oraclize

为此。当 sql数据库上列出人员钱包时,isWhitelisted如何才能返回

1 个答案:

答案 0 :(得分:1)

据我所知,你不能这样检查。 (到目前为止)

但我自己使用的解决方法是使用映射和结构。

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是否可用。如果您提供有关您目前所做工作的更多信息,我可以更好地帮助您。

<强>更新

示例:http://dapps.oraclize.it/browser-solidity/#gist=9817193e5b05206847ed1fcd1d16bd1d&version=soljson-v0.4.21+commit.dfe3193c.js

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”将保存到公共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地址连接到查询网址,您可以查看以下链接: 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"));

将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"}')