def create(wallet, channel_name, asset_type, nonce, sender, sender_balance, receiver, receiver_balance, peer_commitment, comments=None): """ :param wallet: :param channel_name: :param asset_type: :param sender: :param receiver: :param sender_balance: :param receiver_balance: :param peer_commitment: :param status: :return: """ sender_address, _, _ = uri_parser(sender) receiver_address, _, _ = uri_parser(receiver) asset_type = asset_type.upper() # sign the contents commitment = SettleResponseMessage.sign_content( wallet, SettleResponseMessage._sign_type_list, [ channel_name, nonce, sender_address, int(sender_balance), receiver_address, int(receiver_balance) ]) # finally, add the transaction information to database settle_trade = Channel.settle_trade( type=EnumTradeType.TRADE_TYPE_QIUCK_SETTLE, role=EnumTradeRole.TRADE_ROLE_PARTNER, asset_type=asset_type, balance=receiver_balance, peer_balance=sender_balance, commitment=commitment, peer_commitment=peer_commitment) SettleResponseMessage.add_or_update_quick_settle_trade( channel_name, EnumTradeRole.TRADE_ROLE_PARTNER, **settle_trade) message = SettleResponseMessage.create_message_header( receiver, sender, SettleResponseMessage._message_name, channel_name, asset_type, nonce) message.update({"MessageBody": {"Commitment": commitment}}) if not comments: message.update({'Comments': comments}) # send response OK message message.update({'Status': EnumResponseStatus.RESPONSE_OK.name}) Message.send(message)
def create(wallet, receiver, channel_name, asset_type): """ :param channel_name: :param wallet: :param sender: :param receiver: :param asset_type: :return: """ sender = wallet.url channel = Channel(channel_name) nonce = SettleMessage._SETTLE_NONCE asset_type = asset_type.upper() sender_address, _, _, = uri_parser(sender) receiver_address, _, _, = uri_parser(receiver) balance = channel.balance sender_balance = balance.get(sender_address, {}).get(asset_type) receiver_balance = balance.get(receiver_address, {}).get(asset_type) commitment = SettleMessage.sign_content( typeList=SettleMessage._sign_type_list, valueList=[ channel_name, nonce, sender_address, int(sender_balance), receiver_address, int(receiver_balance) ], privtKey=wallet._key.private_key_string) # add trade to database settle_trade = Channel.settle_trade( type=EnumTradeType.TRADE_TYPE_QIUCK_SETTLE, role=EnumTradeRole.TRADE_ROLE_FOUNDER, asset_type=asset_type, balance=sender_balance, peer_balance=receiver_balance, commitment=commitment) SettleMessage.add_or_update_quick_settle_trade( channel_name, EnumTradeRole.TRADE_ROLE_FOUNDER, **settle_trade) # create settle request message message = SettleMessage.create_message_header( sender, receiver, SettleMessage._message_name, channel_name, asset_type, nonce) message = message.message_header message_body = { "Commitment": commitment, "SenderBalance": sender_balance, "ReceiverBalance": receiver_balance } message.update({'MessageBody': message_body}) Message.send(message) return