def get_trx_header(self, seconds_ahead=30): o = fromJson(get_output('cleos get info')) lib = o['last_irreversible_block_num'] exp = parse( o['head_block_time']) + relativedelta(minutes=seconds_ahead) p = fromJson(get_output('cleos get block {}'.format(lib))) return { 'expiration': exp.isoformat(), 'ref_block_num': lib, 'ref_block_prefix': p['ref_block_prefix'] }
def create(self): if not self.is_running(): self.start_wallet() if not os.path.exists(self.wallet_state): os.makedirs(self.wallet_state) o = get_output(self.teclos_start + ' wallet create --to-console') f = open(join(self.wallet_state, 'wallet_pw.txt'), 'w') f.write(self.parse_pw(o))
def create_key(self): try: o = get_output(self.cleos + ' create key --to-console').split("\n") private = o[0][o[0].index(':') + 2:len(o[0])] public = o[1][o[1].index(':') + 2:len(o[1])] return KeyPair(public, private) except ValueError as e: print(e)
def contains_key(self, key): self.unlock() o = get_output(self.cleos + ' wallet private_keys --password %s' % self.get_pw()) j = json.loads(o) for keypair in j: if key == keypair[0] or key == keypair[1]: return True return False
def is_locked(self): try: o = get_output(self.teclos_start + ' wallet list') j = json.loads(o[o.index(':') + 2:len(o)]) for wallet in j: if 'default' in wallet and '*' in wallet: return False return True except ValueError as e: print(e) except OSError as e: print(e)
def wallet_exists(self, wallet_name): try: o = get_output(self.teclos_start + ' wallet list') j = json.loads(o[o.index(':') + 2:len(o)]) for wallet in j: if wallet_name in wallet: print('wallet found: ' + wallet_name) return True #print("wallet not found") return False except ValueError as e: print(e) except OSError as e: print(e)
def get_keys(self): try: self.unlock() o = get_output(self.cleos + ' wallet private_keys --password %s' % self.get_pw()) j = json.loads(o) output = [] for keypair in j: d = {} d['public'] = keypair[0] d['private'] = keypair[1] output.append(d) return output except OSError as e: print(e)