Договор:
contract owned {
function owned() public { owner = msg.sender; }
address owner;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
}
contract TestcontractCrowdSale is owned {
uint public tokens_total = 0;
struct holder {
uint tokens_bonus_balance;
uint tokens_all_balance;
bool tokens_bonus_canspent;
uint ethers_crowdfunded;
uint list_pointer;
}
mapping (address => holder) public holders;
address[] public holdersList;
mapping (address => mapping (address => uint256)) public allowed;
function checkIsHolder(address holderAddress) public constant returns (bool isIndeed) {
if(holdersList.length == 0) return false;
return (holdersList[holders[holderAddress].list_pointer] == holderAddress);
}
function getHoldersCount() public constant returns(uint count) {
return holdersList.length;
}
function newHolder(address holderAddress) public returns(bool success) {
if (!checkIsHolder(holderAddress)) {
/*holders[holderAddress] = holder({
tokens_bonus_balance: 0,
tokens_all_balance: 0,
tokens_bonus_canspent : false,
ethers_crowdfunded : 0,
list_pointer : holdersList.push(holderAddress) - 1
});*/
holders[holderAddress].list_pointer = holdersList.push(holderAddress) - 1;
}
return true;
}
function balanceOf(address tokenOwner) public view returns (uint balance) {
return holders[tokenOwner].tokens_all_balance;
}
function preprint(address _for, uint tokens) onlyOwner public returns (bool printed, address __for, uint bonus_all_tokens) {
newHolder(_for);
holders[_for].tokens_all_balance += tokens;
holders[_for].tokens_bonus_balance += tokens;
holders[_for].tokens_bonus_canspent = false;
tokens_total += tokens;
return (true, _for, holders[_for].tokens_bonus_balance );
}
}
truffle.cmd develop
truffle(develop)> compile
truffle(develop)> migrate
truffle(develop)> TestcontractCrowdSale.deployed().then((instance) => {contract = instance});
truffle(develop)> contract.preprint.call("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"})
[ true,
'0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef',
BigNumber { s: 1, e: 5, c: [ 123456 ] } ]
truffle(develop)> contract.preprint.call("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"})
[ true,
'0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef',
BigNumber { s: 1, e: 5, c: [ 123456 ] } ]
truffle(develop)> contract.balanceOf("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef")
BigNumber { s: 1, e: 0, c: [ 0 ] }
truffle(develop)> contract.tokens_total()
BigNumber { s: 1, e: 0, c: [ 0 ] }
truffle(develop)> contract.tokens_total.call()
BigNumber { s: 1, e: 0, c: [ 0 ] }
Но в ремиксе все работает нормально, функция препринта работает нормально, и я не могу понять, почему? Контракт же!
Это большая проблема для меня.
Вы используете метод web3.js .call в contract.preprint.call()
.
Выполняет транзакцию вызова сообщения, которая выполняется непосредственно в виртуальной машине узла, но никогда не включается в блокчейн.
Изменение команды на truffle(develop)> contract.preprint("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"})
должно исправить это.