def build_offer_create_tx(self, options): tx = Transaction(self, None) if not options: tx.tx_json['obj'] = TypeError('invalid options type') return tx offer_type = options['type'] if options.__contains__('source'): src = options['source'] elif options.__contains__('from'): src = options['from'] elif options.__contains__('account'): src = options['account'] if options.__contains__('taker_gets'): taker_gets = options['taker_gets'] elif options.__contains__('pays'): taker_gets = options['pays'] if options.__contains__('taker_pays'): taker_pays = options['taker_pays'] elif options.__contains__('gets'): taker_pays = options['gets'] if not Wallet.is_valid_address(src): tx.tx_json['src'] = Exception('invalid source address') return tx if not isinstance(offer_type, str) or not offer_type in OfferTypes: tx.tx_json['offer_type'] = TypeError('invalid offer type') return tx if isinstance(taker_gets, str) and not int(taker_gets) and not float(taker_gets): tx.tx_json['taker_gets2'] = Exception('invalid to pays amount') return tx if not taker_gets and not utils.is_valid_amount(taker_gets): tx.tx_json['taker_gets2'] = Exception( 'invalid to pays amount object') return tx if isinstance( taker_pays, str) and not int(taker_pays) and not not float(taker_pays): tx.tx_json['taker_pays2'] = Exception('invalid to gets amount') return tx if not taker_pays and not utils.is_valid_amount(taker_pays): tx.tx_json['taker_pays2'] = Exception( 'invalid to gets amount object') return tx tx.tx_json['TransactionType'] = 'OfferCreate' if offer_type is 'Sell': tx.set_flags(offer_type) tx.tx_json['Account'] = src tx.tx_json['TakerPays'] = to_amount(taker_pays) tx.tx_json['TakerGets'] = to_amount(taker_gets) return tx
def __build_trust_set(self, options, tx): if options.__contains__('source'): src = options['source'] elif options.__contains__('from'): src = options['from'] elif options.__contains__('account'): src = options['account'] limit = options['limit'] if options.__contains__('quality_out'): tx.tx_json['QualityIn'] = options['quality_out'] if options.__contains__('quality_in'): tx.tx_json['QualityOut'] = options['quality_in'] if not Wallet.is_valid_address(src): tx.tx_json['src'] = Exception('invalid source address') return tx if not utils.is_valid_amount(limit): tx.tx_json['limit'] = Exception('invalid amount') return tx tx.tx_json['TransactionType'] = 'TrustSet' tx.tx_json['Account'] = src if limit: tx.tx_json['LimitAmount'] = limit return tx
def __build_relation_set(self, options, tx): if options.__contains__('source'): src = options['source'] elif options.__contains__('from'): src = options['from'] elif options.__contains__('account'): src = options['account'] des = options['target'] limit = options['limit'] if not Wallet.is_valid_address(src): tx.tx_json['src'] = Exception('invalid source address') return tx if not Wallet.is_valid_address(des): tx.tx_json['des'] = Exception('invalid target address') return tx if not utils.is_valid_amount(limit): tx.tx_json['limit'] = Exception('invalid amount') return tx if options['type'] == 'unfreeze': tx.tx_json['TransactionType'] = 'RelationDel' else: tx.tx_json['TransactionType'] = 'RelationSet' tx.tx_json['Account'] = src tx.tx_json['Target'] = des if options['type'] == 'authorize': tx.tx_json['RelationType'] = '1' else: tx.tx_json['RelationType'] = '3' if limit: tx.tx_json['LimitAmount'] = limit return tx
def build_payment_tx(self, options): tx = Transaction(self, None) if not options: tx.tx_json['obj'] = Exception('invalid options type') return tx if options.__contains__('source'): src = options['source'] elif options.__contains__('from'): src = options['from'] elif options.__contains__('account'): src = options['account'] if options.__contains__('destination'): dst = options['destination'] elif options.__contains__('to'): dst = options['to'] amount = options['amount'] if not Wallet.is_valid_address(src): tx.tx_json['src'] = Exception('invalid source address') return tx if not Wallet.is_valid_address(dst): tx.tx_json['dst'] = Exception('invalid destination address') return tx if not utils.is_valid_amount(amount): tx.tx_json['amount'] = Exception('invalid amount') return tx tx.tx_json['TransactionType'] = 'Payment' tx.tx_json['Account'] = src tx.tx_json['Amount'] = to_amount(amount) tx.tx_json['Destination'] = dst return tx