在公司专用网络中,我需要在审计数据收集过程中保护TB级的信息。为此,我需要在一个请求中发送大量数据,为此,我在合同中具有以下功能:
struct Entity {
bytes hash;
bool saved;
}
struct DTO{
string id;
bytes hash;
}
mapping (string => Entity) public Entities;
event EntitySaved(string id, bytes hash);
function SaveEntity(string memory id, bytes memory hash) public {
require(DataProviders[msg.sender]);
Entity storage entity = Entities[id];
require(!entity.saved, 'The entity has already been saved');
entity.hash = hash;
entity.saved = true;
emit EntitySaved(id, hash);
}
function SaveEntities(DTO[] memory _dtos) public {
for (uint i = 0; i < _dtos.length; i++) {
SaveEntity(_dtos[i].id, _dtos[i].hash);
}
}
我正在使用nethereum将数据发送到合同,但这样做有麻烦。此函数不会引发任何错误,但数据不会保存在区块链中:
DTO[] dtos = { new DTO("11", Encoding.UTF8.GetBytes("test11")), new DTO("12", Encoding.UTF8.GetBytes("test12")) };
object[] values = { dtos };
var function = GetFunction("SaveEntities");
gas = await function.EstimateGasAsync( _account.Address, null, null, values);
var receipt = await function.SendTransactionAndWaitForReceiptAsync(_account.Address, gas, null, null, null, values);
public DTO(string id, byte[] hash)
{
this.id = id;
this.hash = hash;
}
protected Function GetFunction(string contractName)
{
var web3 = new Web3(_account, _url);
var contract = web3.Eth.GetContract(_contractAbi, _contractAddress);
var function = contract.GetFunction(contractName);
return function;
}