void domain_buy_operation::evaluate( transaction_evaluation_state& eval_state ) { FC_ASSERT( is_valid_domain( this->domain_name ), "Trying to buy an invalid domain name" ); auto now = eval_state._current_state->now().sec_since_epoch(); auto odomain_rec = eval_state._current_state->get_domain_record( this->domain_name ); /* If it already exists and hasn't expired and you offered enough */ if( odomain_rec.valid() && odomain_rec->get_true_state(now) == domain_record::in_sale && this->price >= odomain_rec->price ) { share_type paid_to_owner = 0; for (auto op : eval_state.trx.operations) { if (op.type == operation_type_enum::deposit_op_type) { auto deposit = op.as<deposit_operation>(); if (deposit.condition.type == withdraw_condition_types::withdraw_signature_type) { auto condition = deposit.condition.as<withdraw_with_signature>(); if (condition.owner == odomain_rec->owner) { paid_to_owner += deposit.amount; } } } } FC_ASSERT( this->price == paid_to_owner ); FC_ASSERT( paid_to_owner >= odomain_rec->price, "Did not pay enough to previous owner" ); odomain_rec->state = domain_record::owned; odomain_rec->owner = this->new_owner; odomain_rec->last_update = eval_state._current_state->now().sec_since_epoch(); eval_state._current_state->store_domain_record( *odomain_rec ); return; } /* Domain does not exist or is not for sale or is too expensive, so this is an offer */ else { auto balance = eval_state._current_state->get_domain_offer(this->new_owner); FC_ASSERT( !balance.valid(), "Trying to make an offer with an offer ID that already exists"); FC_ASSERT(this->price > 0, "Price must be greater than 0 when you offer" ); bool found_deposit = false; for ( auto op : eval_state.trx.operations ) { if (op.type == operation_type_enum::deposit_op_type) { auto deposit = op.as<deposit_operation>(); if( deposit.condition.type == withdraw_condition_types::withdraw_domain_offer_type ) { auto condition = deposit.condition.as<bts::blockchain::withdraw_domain_offer>(); FC_ASSERT( condition.domain_name == this->domain_name, "condition does not match offer op" ); FC_ASSERT( condition.price == this->price, "condition does not match offer op" ); FC_ASSERT( condition.owner == this->new_owner, "condition does not match offer op" ); found_deposit = true; } } } FC_ASSERT( found_deposit, "Did not find a deposit on this domain offer transaction" ); auto offer_key = offer_index_key(); offer_key.price = this->price; offer_key.domain_name = this->domain_name; offer_key.offer_address = this->new_owner; offer_key.offer_time = eval_state._current_state->now().sec_since_epoch(); ulog( "about to store offer\n" ); eval_state._current_state->store_domain_offer( offer_key ); } }
static int is_valid_host(const char *str) { return avs_net_validate_ip_address(AVS_NET_AF_INET4, str) == 0 || avs_net_validate_ip_address(AVS_NET_AF_INET6, str) == 0 || is_valid_domain(str); }