本文整理汇总了Java中org.ethereum.vm.program.invoke.ProgramInvoke类的典型用法代码示例。如果您正苦于以下问题:Java ProgramInvoke类的具体用法?Java ProgramInvoke怎么用?Java ProgramInvoke使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProgramInvoke类属于org.ethereum.vm.program.invoke包,在下文中一共展示了ProgramInvoke类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
private void create() {
byte[] newContractAddress = tx.getContractAddress().getBytes();
if (isEmpty(tx.getData())) {
mEndGas = toBI(tx.getGasLimit()).subtract(BigInteger.valueOf(basicTxCost));
cacheTrack.createAccount(newContractAddress);
} else {
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(tx, txindex, executionBlock, cacheTrack, blockStore);
this.vm = new VM(config);
this.program = new Program(config, tx.getData(), programInvoke, tx);
// reset storage if the contract with the same address already exists
// TCK test case only - normally this is near-impossible situation in the real network
ContractDetails contractDetails = program.getStorage().getContractDetails(newContractAddress);
for (DataWord key : contractDetails.getStorageKeys()) {
program.storageSave(key, DataWord.ZERO);
}
}
BigInteger endowment = toBI(tx.getValue());
transfer(cacheTrack, tx.getSender().getBytes(), newContractAddress, endowment);
}
示例2: ProgramTrace
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
public ProgramTrace(RskSystemProperties config, ProgramInvoke programInvoke) {
if (config.vmTrace() && programInvoke != null) {
contractAddress = Hex.toHexString(programInvoke.getOwnerAddress().getLast20Bytes());
ContractDetails contractDetails = getContractDetails(programInvoke);
if (contractDetails == null) {
storageSize = 0;
fullStorage = true;
} else {
storageSize = contractDetails.getStorageSize();
if (storageSize <= config.vmTraceInitStorageLimit()) {
fullStorage = true;
String address = toHexString(programInvoke.getOwnerAddress().getLast20Bytes());
for (Map.Entry<DataWord, DataWord> entry : contractDetails.getStorage().entrySet()) {
// TODO: solve NULL key/value storage problem
DataWord key = entry.getKey();
DataWord value = entry.getValue();
if (key == null || value == null) {
LOGGER.info("Null storage key/value: address[{}]" ,address);
continue;
}
initStorage.put(key.toString(), value.toString());
}
if (!initStorage.isEmpty()) {
LOGGER.info("{} entries loaded to transaction's initStorage", initStorage.size());
}
}
}
}
}
示例3: getContractDetails
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
private static ContractDetails getContractDetails(ProgramInvoke programInvoke) {
Repository repository = programInvoke.getRepository();
if (repository instanceof RepositoryTrack) {
repository = ((RepositoryTrack) repository).getOriginRepository();
}
byte[] address = programInvoke.getOwnerAddress().getLast20Bytes();
return repository.getContractDetails(address);
}
示例4: Program
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
public Program(RskSystemProperties config, byte[] ops, ProgramInvoke programInvoke) {
this.config = config;
isLogEnabled = logger.isInfoEnabled();
isGasLogEnabled = gasLogger.isInfoEnabled();
if (isLogEnabled ) {
logger.warn("WARNING! VM logging is enabled. This will make the VM 200 times slower. Do not use in production.");
}
if (isGasLogEnabled) {
gasLogger.warn("WARNING! Gas logging is enabled. This will the make VM 200 times slower. Do not use in production.");
}
this.invoke = programInvoke;
this.ops = nullToEmpty(ops);
this.memory = setupProgramListener(new Memory());
this.stack = setupProgramListener(new Stack());
this.stack.ensureCapacity(1024); // faster?
this.storage = setupProgramListener(new Storage(programInvoke));
this.trace = new ProgramTrace(config, programInvoke);
if (useDataWordPool) {
this.dataWordPool = new java.util.Stack<>();
this.dataWordPool.ensureCapacity(1024); // faster?
} else {
this.dataWordPool = null;
}
precompile();
traceListener = new ProgramTraceListener(config);
}
示例5: createProgramInvoke
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
@Override
public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, DataWord callerAddress,
DataWord inValue, long inGas,
BigInteger balanceInt, byte[] dataIn,
Repository repository, BlockStore blockStore, boolean byTestingSuite) {
return null;
}
示例6: Program
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
public Program(byte[] codeHash, byte[] ops, ProgramInvoke programInvoke, Transaction transaction, SystemProperties config) {
this.config = config;
this.invoke = programInvoke;
this.transaction = transaction;
this.codeHash = codeHash == null || FastByteComparisons.equal(HashUtil.EMPTY_DATA_HASH, codeHash) ? null : codeHash;
this.ops = nullToEmpty(ops);
traceListener = new ProgramTraceListener(config.vmTrace());
this.memory = setupProgramListener(new Memory());
this.stack = setupProgramListener(new Stack());
this.storage = setupProgramListener(new Storage(programInvoke));
this.trace = new ProgramTrace(config, programInvoke);
this.blockchainConfig = config.getBlockchainConfig().getConfigForBlock(programInvoke.getNumber().longValue());
}
示例7: createProgramInvoke
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
@Override
public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, DataWord callerAddress,
DataWord inValue, DataWord inGas,
BigInteger balanceInt, byte[] dataIn,
Repository repository, BlockStore blockStore,
boolean isStaticCall, boolean byTestingSuite) {
return null;
}
示例8: executeCode
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
public boolean executeCode(
MessageCall msg,
byte[] contextAddress,
BigInteger contextBalance,
InternalTransaction internalTx,
Repository track,
byte[] programCode,
byte[] senderAddress,
byte[] data ) {
returnDataBuffer = null; // reset return buffer right before the call
ProgramResult childResult = null;
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(
this, new DataWord(contextAddress),
msg.getType() == MsgType.DELEGATECALL ? getCallerAddress() : getOwnerAddress(),
msg.getType() == MsgType.DELEGATECALL ? getCallValue() : msg.getEndowment(),
limitToMaxLong(msg.getGas()), contextBalance, data, track, this.invoke.getBlockStore(), byTestingSuite());
VM vm = new VM(config);
Program program = new Program(config, programCode, programInvoke, internalTx);
vm.play(program);
childResult = program.getResult();
getTrace().merge(program.getTrace());
getResult().merge(childResult );
boolean childCallSuccessful = true;
if (childResult.getException() != null || childResult.isRevert()) {
if (isGasLogEnabled) {
gasLogger.debug("contract run halted by Exception: contract: [{}], exception: [{}]",
Hex.toHexString(contextAddress),
childResult .getException());
}
internalTx.reject();
childResult .rejectInternalTransactions();
childResult.rejectLogInfos();
track.rollback();
// when there's an exception we skip applying results and refunding gas,
// and we only do that when the call is successful or there's a REVERT operation.
if (childResult.getException() != null) {
return false;
}
childCallSuccessful = false;
} else {
// 4. THE FLAG OF SUCCESS IS ONE PUSHED INTO THE STACK
track.commit();
}
// 3. APPLY RESULTS: childResult.getHReturn() into out_memory allocated
byte[] buffer = childResult.getHReturn();
int offset = msg.getOutDataOffs().intValue();
int size = msg.getOutDataSize().intValue();
memorySaveLimited(offset, buffer, size);
returnDataBuffer = buffer;
// 5. REFUND THE REMAIN GAS
BigInteger refundGas = msg.getGas().value().subtract(toBI(childResult.getGasUsed()));
if (isPositive(refundGas)) {
// Since the original gas transferred was < Long.MAX_VALUE then the refund
// also fits in a long.
// SUICIDE refunds 24.000 and SSTORE clear refunds 15.000 gas.
// The accumulated refund can not exceed half the gas used
// for the current context (i.e. the initial call)
// Therefore, the regundGas also fits in a long.
refundGas(refundGas.longValue(), "remaining gas from the internal call");
if (isGasLogEnabled) {
gasLogger.info("The remaining gas refunded, account: [{}], gas: [{}] ",
Hex.toHexString(senderAddress),
refundGas.toString());
}
}
return childCallSuccessful;
}
示例9: Storage
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
public Storage(ProgramInvoke programInvoke) {
this.address = programInvoke.getOwnerAddress();
this.repository = programInvoke.getRepository();
}
示例10: call
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
private void call() {
if (!readyToExecute) {
return;
}
logger.info("Call transaction {} {}", toBI(tx.getNonce()), Hex.toHexString(tx.getHash()));
byte[] targetAddress = tx.getReceiveAddress().getBytes();
// DataWord(targetAddress)) can fail with exception:
// java.lang.RuntimeException: Data word can't exceed 32 bytes:
// if targetAddress size is greater than 32 bytes.
// But init() will detect this earlier
precompiledContract = PrecompiledContracts.getContractForAddress(config, new DataWord(targetAddress));
if (precompiledContract != null) {
precompiledContract.init(tx, executionBlock, track, blockStore, receiptStore, result.getLogInfoList());
long requiredGas = precompiledContract.getGasForData(tx.getData());
BigInteger txGasLimit = toBI(tx.getGasLimit());
if (!localCall && txGasLimit.compareTo(BigInteger.valueOf(requiredGas)) < 0) {
// no refund
// no endowment
execError("Out of Gas calling precompiled contract 0x" + Hex.toHexString(targetAddress) +
", required: " + (requiredGas + basicTxCost) + ", left: " + mEndGas);
mEndGas = BigInteger.ZERO;
return;
} else {
long gasUsed = requiredGas + basicTxCost;
mEndGas = txGasLimit.subtract(BigInteger.valueOf(requiredGas + basicTxCost));
// FIXME: save return for vm trace
try {
byte[] out = precompiledContract.execute(tx.getData());
result.setHReturn(out);
} catch (RuntimeException e) {
result.setException(e);
}
result.spendGas(gasUsed);
}
} else {
byte[] code = track.getCode(targetAddress);
if (isEmpty(code)) {
mEndGas = toBI(tx.getGasLimit()).subtract(BigInteger.valueOf(basicTxCost));
result.spendGas(basicTxCost);
} else {
ProgramInvoke programInvoke =
programInvokeFactory.createProgramInvoke(tx, txindex, executionBlock, cacheTrack, blockStore);
this.vm = new VM(config);
this.program = new Program(config, code, programInvoke, tx);
}
}
if (result.getException() == null) {
BigInteger endowment = toBI(tx.getValue());
transfer(cacheTrack, tx.getSender().getBytes(), targetAddress, endowment);
}
}
示例11: generalInvoke
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
private ProgramInvoke generalInvoke(Transaction tx, int txindex, Repository repository, BlockStore blockStore) {
/*** ADDRESS op ***/
// YP: Get address of currently executing account.
byte[] address = tx.isContractCreation() ? tx.getContractAddress().getBytes() : tx.getReceiveAddress().getBytes();
/*** ORIGIN op ***/
// YP: This is the sender of original transaction; it is never a contract.
byte[] origin = tx.getSender().getBytes();
/*** CALLER op ***/
// YP: This is the address of the account that is directly responsible for this execution.
byte[] caller = tx.getSender().getBytes();
/*** BALANCE op ***/
byte[] balance = repository.getBalance(address).toByteArray();
/*** GASPRICE op ***/
byte[] gasPrice = tx.getGasPrice();
/*** GAS op ***/
byte[] gas = tx.getGasLimit();
/*** CALLVALUE op ***/
byte[] callValue = tx.getValue() == null ? new byte[]{0} : tx.getValue();
/*** CALLDATALOAD op ***/
/*** CALLDATACOPY op ***/
/*** CALLDATASIZE op ***/
byte[] data = tx.isContractCreation() ? ByteUtil.EMPTY_BYTE_ARRAY :( tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData() );
// byte[] data = tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData() ;
/*** PREVHASH op ***/
byte[] lastHash = env.getPreviousHash();
/*** COINBASE op ***/
byte[] coinbase = env.getCurrentCoinbase();
/*** TIMESTAMP op ***/
long timestamp = ByteUtil.byteArrayToLong(env.getCurrentTimestamp());
/*** NUMBER op ***/
long number = ByteUtil.byteArrayToLong(env.getCurrentNumber());
/*** DIFFICULTY op ***/
byte[] difficulty = env.getCurrentDifficulty();
/*** GASLIMIT op ***/
byte[] gaslimit = env.getCurrentGasLimit();
return new ProgramInvokeImpl(address, origin, caller, balance,
gasPrice, gas, callValue, data, lastHash, coinbase,
timestamp, number, txindex, difficulty, gaslimit, repository, blockStore);
}
示例12: ProgramTrace
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
public ProgramTrace(SystemProperties config, ProgramInvoke programInvoke) {
if (programInvoke != null && config.vmTrace()) {
contractAddress = Hex.toHexString(programInvoke.getOwnerAddress().getLast20Bytes());
}
}
示例13: call
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
private void call() {
if (!readyToExecute) return;
byte[] targetAddress = tx.getReceiveAddress();
precompiledContract = PrecompiledContracts.getContractForAddress(new DataWord(targetAddress), blockchainConfig);
if (precompiledContract != null) {
long requiredGas = precompiledContract.getGasForData(tx.getData());
if (!localCall && m_endGas.compareTo(BigInteger.valueOf(requiredGas + basicTxCost)) < 0) {
// no refund
// no endowment
execError("Out of Gas calling precompiled contract 0x" + Hex.toHexString(targetAddress) +
", required: " + (requiredGas + basicTxCost) + ", left: " + m_endGas);
m_endGas = BigInteger.ZERO;
return;
} else {
m_endGas = m_endGas.subtract(BigInteger.valueOf(requiredGas + basicTxCost));
// FIXME: save return for vm trace
Pair<Boolean, byte[]> out = precompiledContract.execute(tx.getData());
if (!out.getLeft()) {
execError("Error executing precompiled contract 0x" + Hex.toHexString(targetAddress));
m_endGas = BigInteger.ZERO;
return;
}
}
} else {
byte[] code = track.getCode(targetAddress);
if (isEmpty(code)) {
m_endGas = m_endGas.subtract(BigInteger.valueOf(basicTxCost));
result.spendGas(basicTxCost);
} else {
ProgramInvoke programInvoke =
programInvokeFactory.createProgramInvoke(tx, currentBlock, cacheTrack, blockStore);
this.vm = new VM(config);
this.program = new Program(track.getCodeHash(targetAddress), code, programInvoke, tx, config).withCommonConfig(commonConfig);
}
}
BigInteger endowment = toBI(tx.getValue());
transfer(cacheTrack, tx.getSender(), targetAddress, endowment);
touchedAccounts.add(targetAddress);
}
示例14: create
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
private void create() {
byte[] newContractAddress = tx.getContractAddress();
AccountState existingAddr = cacheTrack.getAccountState(newContractAddress);
if (existingAddr != null && existingAddr.isContractExist(blockchainConfig)) {
execError("Trying to create a contract with existing contract address: 0x" + Hex.toHexString(newContractAddress));
m_endGas = BigInteger.ZERO;
return;
}
//In case of hashing collisions (for TCK tests only), check for any balance before createAccount()
BigInteger oldBalance = track.getBalance(newContractAddress);
cacheTrack.createAccount(tx.getContractAddress());
cacheTrack.addBalance(newContractAddress, oldBalance);
if (blockchainConfig.eip161()) {
cacheTrack.increaseNonce(newContractAddress);
}
if (isEmpty(tx.getData())) {
m_endGas = m_endGas.subtract(BigInteger.valueOf(basicTxCost));
result.spendGas(basicTxCost);
} else {
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(tx, currentBlock, cacheTrack, blockStore);
this.vm = new VM(config);
this.program = new Program(tx.getData(), programInvoke, tx, config).withCommonConfig(commonConfig);
// reset storage if the contract with the same address already exists
// TCK test case only - normally this is near-impossible situation in the real network
// TODO make via Trie.clear() without keyset
// ContractDetails contractDetails = program.getStorage().getContractDetails(newContractAddress);
// for (DataWord key : contractDetails.getStorageKeys()) {
// program.storageSave(key, DataWord.ZERO);
// }
}
BigInteger endowment = toBI(tx.getValue());
transfer(cacheTrack, tx.getSender(), newContractAddress, endowment);
touchedAccounts.add(newContractAddress);
}
示例15: generalInvoke
import org.ethereum.vm.program.invoke.ProgramInvoke; //导入依赖的package包/类
private ProgramInvoke generalInvoke(Transaction tx, Repository repository, BlockStore blockStore) {
/*** ADDRESS op ***/
// YP: Get address of currently executing account.
byte[] address = tx.isContractCreation() ? tx.getContractAddress() : tx.getReceiveAddress();
/*** ORIGIN op ***/
// YP: This is the sender of original transaction; it is never a contract.
byte[] origin = tx.getSender();
/*** CALLER op ***/
// YP: This is the address of the account that is directly responsible for this execution.
byte[] caller = tx.getSender();
/*** BALANCE op ***/
byte[] balance = repository.getBalance(address).toByteArray();
/*** GASPRICE op ***/
byte[] gasPrice = tx.getGasPrice();
/*** GAS op ***/
byte[] gas = tx.getGasLimit();
/*** CALLVALUE op ***/
byte[] callValue = tx.getValue() == null ? new byte[]{0} : tx.getValue();
/*** CALLDATALOAD op ***/
/*** CALLDATACOPY op ***/
/*** CALLDATASIZE op ***/
byte[] data = tx.isContractCreation() ? ByteUtil.EMPTY_BYTE_ARRAY :( tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData() );
// byte[] data = tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData() ;
/*** PREVHASH op ***/
byte[] lastHash = env.getPreviousHash();
/*** COINBASE op ***/
byte[] coinbase = env.getCurrentCoinbase();
/*** TIMESTAMP op ***/
long timestamp = ByteUtil.byteArrayToLong(env.getCurrentTimestamp());
/*** NUMBER op ***/
long number = ByteUtil.byteArrayToLong(env.getCurrentNumber());
/*** DIFFICULTY op ***/
byte[] difficulty = env.getCurrentDifficulty();
/*** GASLIMIT op ***/
byte[] gaslimit = env.getCurrentGasLimit();
return new ProgramInvokeImpl(address, origin, caller, balance,
gasPrice, gas, callValue, data, lastHash, coinbase,
timestamp, number, difficulty, gaslimit, repository, blockStore);
}