def onNEP17Payment(t_from: UInt160, t_amount: int, data: List[Any]): """ Triggered by a payment to the contract, which creates a new stream Args: t_from (UInt160): Sender of GAS t_amount (int): Amount of GAS sent data (List[Any]): Parameters for operations """ if calling_script_hash == GAS: assert len(t_from) == 20, 'invalid address' assert t_amount > 0, 'no funds transferred' p_len = len(data) assert p_len > 1, 'incorrect data length' p_operation = cast(str, data[0]) if p_operation == 'createStream': assert p_len == 4, 'incorrect arguments to createStream' recipient = cast(bytes, data[1]) start_time = cast(int, data[2]) stop_time = cast(int, data[3]) current_time = get_time assert len(recipient) == 20, 'invalid recipient scripthash' # assert start_time >= current_time, 'start time cannot be in the past' assert stop_time > start_time, 'stop time must be greater than start time' stream = newStream() stream['start'] = start_time stream['stop'] = stop_time stream['deposit'] = t_amount stream['remaining'] = t_amount stream['sender'] = base64_encode(t_from) stream['recipient'] = base64_encode(recipient) saveStream(stream) return abort()
def getSenderStreams(sender: UInt160) -> str: """ Get all streams where address is sender Args: sender (UInt160): address as UInt160 Returns: str: JSON array of stream IDs """ sender64 = base64_encode(sender) streams = find('bysender/' + sender64) ret = '' while streams.next(): ret = ret + itoa(cast(bytes, streams.value[1]).to_int()) + ',' if len(ret) > 0: ret = '[' + ret[:-1] return ret + ']' return '[]'
def getRecipientStreams(recipient: UInt160) -> str: """ Get all streams where address is recipient Args: recipient (UInt160): address as UInt160 Returns: str: JSON array of stream IDs """ recipient64 = base64_encode(recipient) streams = find('byrecipient/' + recipient64) ret = '' while streams.next(): ret = ret + itoa(cast(bytes, streams.value[1]).to_int()) + ',' if len(ret) > 0: ret = '[' + ret[:-1] return ret + ']' return '[]'
def Main(key: bytes) -> str: return base64_encode(key)
def Main(key: int) -> bytes: return base64_encode(key)