Ich habe diesen Code:
pragma solidity ^0.4.11;
contract Bank {
struct Balance {
address owner;
uint vault;
uint profit;
}
Balance balance;
mapping (address => uint) balances;
function Bank() {
balance.owner = msg.sender;
balance = Balance(msg.sender, 0, 0);
}
function getBalance() constant returns (uint) {
if(msg.sender == balance.owner) {
return this.balance;
}
throw;
}
function withdrawOwner() returns (bool) {
if(msg.sender == balance.owner) {
balance.vault = balance.vault - balance.profit;
bool sent = balance.owner.send(balance.profit);
balance.profit = 0;
return sent;
}
return false;
}
function withdraw() returns (bool) {
uint customerBalance = balances[msg.sender];
if(customerBalance == 0) {
throw;
}
balance.vault -= customerBalance;
balances[msg.sender] = 0;
return msg.sender.send(customerBalance);
}
function deposit() payable returns (bool) {
uint take = 100;
uint depositAmount = msg.value;
balance.vault += depositAmount;
balance.profit += take;
balances[msg.sender] = depositAmount - take;
if(msg.value < 20) {
throw;
}
return true;
}
}
Schätzung Gas sagt 4.700.000, was hoch erscheint. Liegt das am Werfen oder am Senden? Wenn man das bei einem Etherpreis von rund 200 $ urteilt, würde das 18 $ kosten?
Ich multipliziere 20Gwei * 4,7e6 = 94000000000000000 = 0,094 Ether
Ich habe Ihrem Beispiel eine Scheinstruktur und ein Mock-Mapping hinzugefügt und es in Remix kompiliert.
pragma solidity ^0.4.11;
// mock contracts
contract c{
// mock mapping
mapping (address=>uint) balances;
// mock struct
struct foo {
uint vault;
}
function withdraw() returns (bool) {
// init struct
foo memory balance;
uint customerBalance = balances[msg.sender];
if(customerBalance == 0) {
throw;
}
balance.vault -= customerBalance;
balances[msg.sender] = 0;
return msg.sender.send(customerBalance);
}
}
Der Compiler kehrt zurück. Sie geben Ihr Benzin woanders aus. Bitte geben Sie den vollständigen Vertrag an.
Transaktionskosten: 160457 Gas. Ausführungskosten: 81525 Gas.
UPD: Volle Vertragskosten
Transaktionskosten: 379244 Gas. Ausführungskosten: 245228 Gas.
Result: "0x0000000000000000000000000000000000000000000000000000000000000001" Transaction cost: 23673 gas. Execution cost: 17401 gas. Decoded: bool: true
zum Zurückziehen in Remix
0xCrema.eth
Justin Thomas
VincentLg