def print_tokendata(tokenStatus): #print token status for i in range(0, len(tokenStatus)): if (i == 4 or i == 5): dt = DatetimeUtil.timestamp_datetime(tokenStatus[i]) #dt=datetime.datetime.utcfromtimestamp(token_data[i]/1e3) print(DatetimeUtil.datetime_string(dt)) #print(DatetimeUtil.datetime_timestamp(dt)) #print(token_data[i]) else: print(tokenStatus[i])
def is_condition_valid(condition_data): if(condition_data==[]): return True #handle Timespan if(condition_data['type']=='Timespan'): #print condition_data['value']['start'] starttime = DatetimeUtil.string_datetime(condition_data['value']['start'], "%H:%M:%S") endtime = DatetimeUtil.string_datetime(condition_data['value']['end'], "%H:%M:%S") nowtime=DatetimeUtil.string_datetime(timestr, "%H:%M:%S") '''print(starttime) print(endtime) print(nowtime)''' #check if timespan condition is valid if(not (starttime<nowtime<endtime) ): print("condition validation fail!") return False return True
def print_tokendata(token_data): #print token status for i in range(0, len(token_data[0])): if (i == 3 or i == 4): dt = DatetimeUtil.timestamp_datetime(token_data[0][i]) #dt=datetime.datetime.utcfromtimestamp(token_data[i]/1e3) print(DatetimeUtil.datetime_string(dt)) #print(DatetimeUtil.datetime_timestamp(dt)) #print(token_data[i]) else: print(token_data[0][i]) #print delegation status for i in range(0, len(token_data[1])): print(token_data[1][i]) #print authprization status print(token_data[2])
def is_token_valid(token_data): ret = True #check enable flag if( token_data['initialized']!=True or token_data['isValid']!=True): ret = False #check issue time and expire time now_stamp = DatetimeUtil.datetime_timestamp(datetime.datetime.now()) if( (token_data['issuedate'] > now_stamp) or (now_stamp > token_data['expireddate']) ): ret = False return ret
def calculate_blocktime(block_number, curr_blkNum=0): #get current block number to search back if (curr_blkNum == 0): blk_number = web3.eth.blockNumber else: blk_number = curr_blkNum sum_time = 0 skip_count = 0 for i in range(0, block_number - 1): blk = web3.eth.getBlock(blk_number - i) dt = DatetimeUtil.timestamp_datetime(blk.timestamp * 1000) #print(DatetimeUtil.datetime_string(dt)) time_diff = web3.eth.getBlock( blk_number - i).timestamp - web3.eth.getBlock(blk_number - i - 1).timestamp if (time_diff > 60): skip_count += 1 else: sum_time += time_diff #print(time_diff) #print(skip_count) ave_blocktime = sum_time / (block_number - skip_count) return ave_blocktime
"--------------------------------------------------------------------") # list Access control '''json_data=TypesUtil.string_to_json(token_data[-1]) print("resource: %s" %(json_data['resource'])) print("action: %s" %(json_data['action'])) print("conditions: %s" %(json_data['conditions']))''' # ----------------------------------- Send transact -------------------------- #========== set master of domain ======== #myCapACtoken.assignVZoneMaster(node_address); #myCapACtoken.revokeVZoneMaster() # ========= set capability flag ======== #myCapACtoken.initCapToken(node_address); #myCapACtoken.setCapToken_isValid(node_address, True) # ============= set issue date and expired date ========== nowtime = datetime.datetime.now() #calculate issue_time and expire_time issue_time = DatetimeUtil.datetime_timestamp(nowtime) duration = DatetimeUtil.datetime_duration(0, 1, 0, 0) expire_time = DatetimeUtil.datetime_timestamp(nowtime + duration) #myCapACtoken.setCapToken_expireddate(node_address, issue_time, expire_time) #set access right #access_right='{"resource":"/BlendCAC/api/v1.0/getCapToken", "action":"GET", "conditions":{"value": {"start": "10:08:32", "end": "23:32:32"},"type": "Timespan"}}'; #myCapACtoken.setCapToken_authorization(node_address, access_right) pass