We are setting up something akin to a blockchain explorer, but our Eth fullnode seems to be missing transaction info for certain blocks.
For instance, I can query eth.getTransaction but eth.getTransactionReceipt returns null
> eth.getTransaction('0x03a05ea076149ae8cff6b0fbc9b1f29c6bf6b7ab04ded92080c54084688456dd')
{
blockHash: "0xfd3b78d9b56e9a911beda3ff488c28c9dd83a9ae4961ba676f852e316cffde89",
blockNumber: 5035686,
from: "0x0ce287cc90601a891e65efda7037f5682cb1ade6",
gas: 210000,
gasPrice: 40000000000,
hash: "0x03a05ea076149ae8cff6b0fbc9b1f29c6bf6b7ab04ded92080c54084688456dd",
input: "0x",
nonce: 21,
r: "0x464f05819d48288db06cac5ff21b49d02a1250df6c4ba1e20ecdb38c558e5b44",
s: "0x1f48c4531a3807b987857b99639b51f54e3718b9f1d808d66ad765ee0f71aba0",
to: "0xe4bad5a72c04d5473e932f54036376772378b83d",
transactionIndex: 72,
v: "0x26",
value: 98082570000000016
}
eth.getTransactionReceipt('0x03a05ea076149ae8cff6b0fbc9b1f29c6bf6b7ab04ded92080c54084688456dd')
null
Is there a reason why this would happen, and are there any solutions other than a full resync?
I do believe that the first time that I synced the blockchain I used --fast, so potentially it missed some txs, although this parameter is poorly documented.
It looks like there's an issue with your node. The receipt is returned from Infura. I'd recommend resync without --fast.
truffle(liveI)> web3.eth.getTransactionReceipt('0x03a05ea076149ae8cff6b0fbc9b1f29c6bf6b7ab04ded92080c54084688456dd', (e, r) => console.log(r));
undefined
truffle(liveI)> { blockHash: '0xfd3b78d9b56e9a911beda3ff488c28c9dd83a9ae4961ba676f852e316cffde89',
blockNumber: 5035686,
contractAddress: null,
cumulativeGasUsed: 2154783,
from: '0x0ce287cc90601a891e65efda7037f5682cb1ade6',
gasUsed: 21000,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: '0x1',
to: '0xe4bad5a72c04d5473e932f54036376772378b83d',
transactionHash: '0x03a05ea076149ae8cff6b0fbc9b1f29c6bf6b7ab04ded92080c54084688456dd',
transactionIndex: 72 }
if you get null, then firstly do miner.start() and then after few blocks are mined, stop mining and then try getting the transactionReceipt.
FYI: It worked for me.
Related
I have a json file:
[
{
"name": "John",
"sirname": "Fogerty",
"age": 77
},
{
"name": "Dave",
"sirname": "Mustaine",
"age": 61
}
]
I want to read the objects of the User structure from it into an array, then add another element to this array and re-write everything to the same file.
My code:
use serde_derive::{Serialize, Deserialize};
use serde_json::json;
use std::fs::File;
#[derive(Serialize, Deserialize, Debug)]
struct User {
name: String,
sirname: String,
age: u8,
}
fn main() {
let f = File::open("info.json").unwrap();
let mut q: Vec<User> = serde_json::from_reader(&f).unwrap();
q.push(User{name: "Daniil".to_string(),
sirname: "Volkov".to_string(),
age: 19,
});
serde_json::to_writer(f, &q).unwrap();
println!("{:?}", q);
}
I get an error when starting:
thread 'main' panicked at 'called Result::unwrap() on an Err value: Error("Access denied. (os error 5)", line: 0, column: 0)', src\main.rs:22:34
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
error: process didn't exit successfully: target\debug\json.exe (exit code: 101).
What do I need to do?
As noted by #Caesar in comments, you should change the way you open your file. Thus instead of
let f = File::open("info.json").unwrap();
you should put the following:
let mut f = File::options()
.read(true)
.write(true)
.open("info.json")
.unwrap();
But as you read your file your position in that file moves, so before writing to the file (since you are willing to rewrite it, not append) you need to reset the position:
let _ = f.seek(std::io::SeekFrom::Start(0)).unwrap();
right before the following line:
serde_json::to_writer(f, &q).unwrap();
i have a json result:
0: { m_event_type_id: 0, m_event_log_description: "SYSTEM_LOG_44: RPM Reduction Due to High Wind Turbulence OFF", …}
1: { m_event_type_id: 0, m_event_log_description: "SYSTEM_LOG_44: RPM Reduction Due to High Wind Turbulence ON", …}
2: { m_event_type_id: 0, m_event_log_description: "Grease Pump Stopped 30 cycles executed", …}
3: { m_event_type_id: 0, m_event_log_description: "Grease Pump Started", …}
4: { m_event_type_id: 0, m_event_log_description: "SYSTEM_LOG_40: Battery Test Request Signal ON", …}
my result is stored in a variable call rslt,now i want to access
rslt.m_event_log_description
but it gives me error because cant access the property like this,any way to achive it?i dont want to write rslt[0].m_event_log_description because it just gives me the first one
You could use the Array#map function to extract a property from an object array as an array.
Try the following
someService.getData().subscribe(
response => {
this.rslt = response;
this.logDescriptions = response.map(item => item['m_event_log_description']);
},
error => {
// handle error
}
);
Now you could use the logDescriptions property in the template
<div *ngFor="description of logDescriptions">
{{ description }}
</div>
I'm getting this string as query result from my database:
"%Sample.Struct{list: [], total: \"0.00\", day: 6, id: \"8vfts6\"}"
Is there any way to convert this one back to map?
I'm getting this error decoding it with poison
** (Poison.SyntaxError) Unexpected token: %
(poison) lib/poison/parser.ex:56: Poison.Parser.parse!/2
(poison) lib/poison.ex:83: Poison.decode!/2
I can't fix the way data is being added to database, i must find a proper way for a key/value route to easily retrive data from that. (this is just a sample for a more complex result)
As it was mentioned in comments, you should not use Code.eval_string. But, there is a way to safely convert your code to Elixir struct, using Code module:
ex(1)> encoded = "%Sample.Struct{list: [], total: \"0.00\", day: 6, id: \"8vfts6\"}"
"%Sample.Struct{list: [], total: \"0.00\", day: 6, id: \"8vfts6\"}"
First, get the AST from the string, but use the pattern matching to ensure it is a struct you are looking for ({:__aliases__, _, [:Sample, :Struct]}). All other (potentially malicious) code will fail this match:
iex(2)> {:ok, {:%, _, [{:__aliases__, _, [:Sample, :Struct]}, {:%{}, _, keymap}]} = ast} = Code.string_to_quoted(encoded)
{:ok,
{:%, [line: 1],
[{:__aliases__, [line: 1], [:Sample, :Struct]},
{:%{}, [line: 1], [list: [], total: "0.00", day: 6, id: "8vfts6"]}]}}
Here you have the full ast for you struct, and the keymap. You may now be tempted to use eval_quoted with the AST, to get the struct you needed:
iex(3)> {struct, _} = Code.eval_quoted(ast)
{%Sample.Struct{day: 6, id: "8vfts6", list: [], total: "0.00"}, []}
iex(4)> struct
%Sample.Struct{day: 6, id: "8vfts6", list: [], total: "0.00"}
But it is still not safe! Someone may put a function causing side effect into the string, like "%Sample.Struct{list: IO.puts \"Something\"}", which will be executed during the evaluation. So you will need to check the keymap firsts, if it contain safe data.
Or you may just use keymap directly, without evaluating anyting:
iex(5)> struct(Sample.Struct, keymap)
%Sample.Struct{day: 6, id: "8vfts6", list: [], total: "0.00"}
Sails.js version 0.12.13.
User.query(`CALL someProc()`, function(err, data){
console.log(data);
}
Response:
data: OkPacket {
fieldCount: 0,
affectedRows: 0,
insertId: 0,
serverStatus: 32,
warningCount: 0,
message: '',
protocol41: true,
changedRows: 0
}
What means "serverStatus: 32"?
And what means "serverStatus: 34"?
The response from a .query call in Sails comes directly from the driver, in this case mysql. The serverStatus is a bitfield. You can get the list of constants in the MySQL source code docs -- the first one in the list represents a value of 1, the next 2, then 4, etc.
So serverStatus: 32 means that only the sixth bit is set, corresponding to SERVER_STATUS_CURSOR_EXISTS:
The server was able to fulfill the clients request and opened a read-only non-scrollable cursor for a query.
This flag comes in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands. Used by Binary Protocol Resultset to signal that COM_STMT_FETCH must be used to fetch the row-data.
If you see serverStatus: 34, it means both the above and the second bit, SERVER_STATUS_AUTOCOMMIT, was set:
Server in auto_commit mode.
Guys I'm using a select() tag in .html.erb file as follows
<%= select(:hfi_id, b.beneficiaryloans.collect { |h| [User.find(h.hfi_id).firstname, h.hfi_id] }) %>
what's wrong in this statement? actually it is giving an error called
wrong number of arguments (2 for 3) - error for above line
But same thing I executed in irb console, it's working fine like
irb(main):012:0> me=Beneficiary.find(1)
=> #<Beneficiary id: 1, firstname: "Mohan", lastname: "Bairwa", address: "1399 m.k.b jagatpira", age: 24, sex: "Male", total_members: 1, cso_id: 123, project_id: 17, remarks: nil, status_id: 4, created_at: "2011-11-07 09:39:24", updated_at: "2011-11-07 09:55:07">
irb(main):018:0> me.beneficiaryloans.collect {|h|User.find(h.hfi_id).firstname,h.hfi_id]}
=> [["Gruh", 117]]
using irb console I'm getting correct result
=> [["Gruh", 117]]
but when I put it in .html.erb file, It's giving argument error. How to solve this?
Look at this. select method has 3 obligatory parameters and you provide only two..