fix: optional name for auction v1

This commit is contained in:
Vecheslav Druzhbin 2021-07-28 14:31:59 +03:00
parent 9f83796566
commit ff4ed1b18a
5 changed files with 32 additions and 16 deletions

View File

@ -1,3 +1,5 @@
use solana_clap_utils::input_parsers::value_of;
use {
clap::{crate_description, crate_name, crate_version, App, Arg, ArgMatches, SubCommand},
rand::Rng,
@ -33,7 +35,7 @@ fn string_to_array(value: &str) -> [u8; 32] {
fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
use spl_auction::{
instruction,
processor::{CreateAuctionArgs, PriceFloor, WinnerLimit},
processor::{CreateAuctionArgsV2, PriceFloor, WinnerLimit},
PREFIX,
};
@ -65,7 +67,10 @@ fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
// Optional auction name
let name: &str = app_matches.value_of("name").unwrap_or("");
// Optional instant sale price
let instant_sale_price: Option<u64> = value_of::<u64>(app_matches, "instant_sale_price");
println!(
"Creating Auction:\n\
- Auction: {}\n\
@ -118,10 +123,10 @@ fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
let instructions = [
// Create an auction for the auction seller as their own resource.
instruction::create_auction_instruction(
instruction::create_auction_instruction_v2(
program_key,
payer.pubkey(),
CreateAuctionArgs {
CreateAuctionArgsV2 {
authority: payer.pubkey(),
end_auction_at: None,
end_auction_gap: None,
@ -132,6 +137,7 @@ fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
gap_tick_size_percentage: Some(0),
tick_size: Some(0),
name,
instant_sale_price,
},
),
];
@ -625,6 +631,13 @@ fn main() {
.takes_value(true)
.help("Optional auction name (up to 32 characters long)."),
)
.arg(
Arg::with_name("instant_sale_price")
.long("instant-sale-price")
.value_name("AMOUNT")
.takes_value(true)
.help("Optional instant sale price."),
)
)
.subcommand(
SubCommand::with_name("inspect")

View File

@ -36,7 +36,9 @@ pub fn process_instruction(
match AuctionInstruction::try_from_slice(input)? {
AuctionInstruction::CancelBid(args) => cancel_bid(program_id, accounts, args),
AuctionInstruction::ClaimBid(args) => claim_bid(program_id, accounts, args),
AuctionInstruction::CreateAuction(args) => create_auction(program_id, accounts, args, None),
AuctionInstruction::CreateAuction(args) => {
create_auction(program_id, accounts, args, None, None)
}
AuctionInstruction::CreateAuctionV2(args) => create_auction_v2(program_id, accounts, args),
AuctionInstruction::EndAuction(args) => end_auction(program_id, accounts, args),
AuctionInstruction::PlaceBid(args) => place_bid(program_id, accounts, args),
@ -93,6 +95,9 @@ pub struct AuctionData {
pub bid_state: BidState,
}
// Alias for auction name.
pub type AuctionName = [u8; 32];
pub const MAX_AUCTION_DATA_EXTENDED_SIZE: usize = 8 + 9 + 2 + 9 + 191;
// Further storage for more fields. Would like to store more on the main data but due
// to a borsh issue that causes more added fields to inflict "Access violation" errors
@ -110,7 +115,7 @@ pub struct AuctionDataExtended {
/// Instant sale price
pub instant_sale_price: Option<u64>,
/// Auction name
pub name: [u8; 32],
pub name: Option<AuctionName>,
}
impl AuctionDataExtended {

View File

@ -3,8 +3,8 @@ use mem::size_of;
use crate::{
errors::AuctionError,
processor::{
AuctionData, AuctionDataExtended, AuctionState, Bid, BidState, PriceFloor, WinnerLimit,
BASE_AUCTION_DATA_SIZE, MAX_AUCTION_DATA_EXTENDED_SIZE,
AuctionData, AuctionDataExtended, AuctionName, AuctionState, Bid, BidState, PriceFloor,
WinnerLimit, BASE_AUCTION_DATA_SIZE, MAX_AUCTION_DATA_EXTENDED_SIZE,
},
utils::{assert_derivation, assert_owned_by, create_or_allocate_account_raw},
EXTENDED, PREFIX,
@ -44,8 +44,6 @@ pub struct CreateAuctionArgs {
pub tick_size: Option<u64>,
/// Add a minimum percentage increase each bid must meet.
pub gap_tick_size_percentage: Option<u8>,
/// Auction name
pub name: [u8; 32],
}
struct Accounts<'a, 'b: 'a> {
@ -76,6 +74,7 @@ pub fn create_auction(
accounts: &[AccountInfo],
args: CreateAuctionArgs,
instant_sale_price: Option<u64>,
name: Option<AuctionName>,
) -> ProgramResult {
msg!("+ Processing CreateAuction");
let accounts = parse_accounts(program_id, accounts)?;
@ -160,7 +159,7 @@ pub fn create_auction(
tick_size: args.tick_size,
gap_tick_size_percentage: args.gap_tick_size_percentage,
instant_sale_price,
name: args.name,
name,
}
.serialize(&mut *accounts.auction_extended.data.borrow_mut())?;

View File

@ -4,8 +4,8 @@ use crate::{
errors::AuctionError,
processor::create_auction::*,
processor::{
AuctionData, AuctionDataExtended, AuctionState, Bid, BidState, PriceFloor, WinnerLimit,
BASE_AUCTION_DATA_SIZE, MAX_AUCTION_DATA_EXTENDED_SIZE,
AuctionData, AuctionDataExtended, AuctionName, AuctionState, Bid, BidState, PriceFloor,
WinnerLimit, BASE_AUCTION_DATA_SIZE, MAX_AUCTION_DATA_EXTENDED_SIZE,
},
utils::{assert_derivation, assert_owned_by, create_or_allocate_account_raw},
EXTENDED, PREFIX,
@ -46,7 +46,7 @@ pub struct CreateAuctionArgsV2 {
/// Add a minimum percentage increase each bid must meet.
pub gap_tick_size_percentage: Option<u8>,
/// Auction name
pub name: [u8; 32],
pub name: AuctionName,
/// Add a instant sale price.
pub instant_sale_price: Option<u64>,
}
@ -92,8 +92,8 @@ pub fn create_auction_v2(
price_floor: args.price_floor,
tick_size: args.tick_size,
gap_tick_size_percentage: args.gap_tick_size_percentage,
name: args.name,
},
args.instant_sale_price,
Some(args.name),
)
}

View File

@ -195,7 +195,6 @@ pub async fn create_auction(
price_floor,
gap_tick_size_percentage,
tick_size,
name: string_to_array(name)?,
},
)],
Some(&payer.pubkey()),