// Run a contract's code on an isolated and unpersisted state // Cannot be used to create new contracts func (this *transactor) Call(fromAddress, toAddress, data []byte) (*Call, error) { st := this.consensusState.GetState() // performs a copy cache := state.NewBlockCache(st) outAcc := cache.GetAccount(toAddress) if outAcc == nil { return nil, fmt.Errorf("Account %X does not exist", toAddress) } if fromAddress == nil { fromAddress = []byte{} } callee := toVMAccount(outAcc) caller := &vm.Account{Address: cmn.LeftPadWord256(fromAddress)} txCache := state.NewTxCache(cache) params := vm.Params{ BlockHeight: int64(st.LastBlockHeight), BlockHash: cmn.LeftPadWord256(st.LastBlockHash), BlockTime: st.LastBlockTime.Unix(), GasLimit: 10000000, } vmach := vm.NewVM(txCache, params, caller.Address, nil) vmach.SetFireable(this.eventSwitch) gas := int64(1000000000) ret, err := vmach.Call(caller, callee, callee.Code, data, 0, &gas) if err != nil { return nil, err } return &Call{Return: hex.EncodeToString(ret)}, nil }
// No idea what this does. func toVMAccount(acc *account.Account) *vm.Account { return &vm.Account{ Address: cmn.LeftPadWord256(acc.Address), Balance: acc.Balance, Code: acc.Code, Nonce: int64(acc.Sequence), Other: acc.PubKey, } }
// Run the given code on an isolated and unpersisted state // Cannot be used to create new contracts. func (this *transactor) CallCode(fromAddress, code, data []byte) (*Call, error) { if fromAddress == nil { fromAddress = []byte{} } st := this.consensusState.GetState() // performs a copy cache := this.mempoolReactor.Mempool.GetCache() callee := &vm.Account{Address: cmn.LeftPadWord256(fromAddress)} caller := &vm.Account{Address: cmn.LeftPadWord256(fromAddress)} txCache := state.NewTxCache(cache) params := vm.Params{ BlockHeight: int64(st.LastBlockHeight), BlockHash: cmn.LeftPadWord256(st.LastBlockHash), BlockTime: st.LastBlockTime.Unix(), GasLimit: 10000000, } vmach := vm.NewVM(txCache, params, caller.Address, nil) gas := int64(1000000000) ret, err := vmach.Call(caller, callee, code, data, 0, &gas) if err != nil { return nil, err } return &Call{Return: hex.EncodeToString(ret)}, nil }
// Get the value stored at 'key' in the account with address 'address' // Both the key and value is returned. func (this *accounts) StorageAt(address, key []byte) (*StorageItem, error) { state := this.consensusState.GetState() account := state.GetAccount(address) if account == nil { return &StorageItem{key, []byte{}}, nil } storageRoot := account.StorageRoot storageTree := state.LoadStorage(storageRoot) _, value := storageTree.Get(cmn.LeftPadWord256(key).Bytes()) if value == nil { return &StorageItem{key, []byte{}}, nil } return &StorageItem{key, value.([]byte)}, nil }