<s> """<STR_LIT>""" <EOL> import json , logging <EOL> def validate_rpc ( content ) : <EOL> """<STR_LIT>""" <EOL> if type ( content ) != type ( { } ) : <EOL> return False <EOL> required = { '<STR_LIT>' : None , '<STR_LIT:id>' : None , '<STR_LIT>' : '<STR_LIT>' } <EOL> for key , value in required . items ( ) : <EOL> if key not in content : <EOL> return False <EOL> if value and content [ key ] != value : <EOL> return False <EOL> return True <EOL> def validate_rpc_recieved ( content ) : <EOL> """<STR_LIT>""" <EOL> required = { '<STR_LIT:result>' : None , '<STR_LIT:id>' : None , '<STR_LIT:error>' : None } <EOL> for key , value in required . items ( ) : <EOL> if key not in content : <EOL> return False <EOL> if value and content [ key ] != value : <EOL> return False <EOL> return True <EOL> def extract_merkle ( content ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in content : <EOL> logging . info ( '<STR_LIT>' ) <EOL> return None <EOL> if len ( content [ '<STR_LIT>' ] ) != <NUM_LIT:1> : <EOL> logging . info ( '<STR_LIT>' ) <EOL> return None <EOL> if len ( content [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) < <NUM_LIT> : <EOL> logging . info ( '<STR_LIT>' ) <EOL> return None <EOL> merkle = content [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT> : <NUM_LIT> ] <EOL> return merkle <EOL> def extract_merkle_recieved ( content ) : <EOL> """<STR_LIT>""" <EOL> if not validate_rpc_recieved ( content ) : <EOL> return None <EOL> merkle = content [ '<STR_LIT:result>' ] [ '<STR_LIT:data>' ] [ <NUM_LIT> : <NUM_LIT> ] <EOL> return merkle <EOL> def extract_result ( content ) : <EOL> """<STR_LIT>""" <EOL> result = content [ '<STR_LIT:result>' ] <EOL> return result <EOL> def rpc_error ( message = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return json . dumps ( { "<STR_LIT:result>" : None , '<STR_LIT:error>' : { '<STR_LIT:message>' : message } , '<STR_LIT:id>' : <NUM_LIT:1> } ) </s>
