func (db *DB) ViewAuctionPuzzleBook(auctionID [32]byte) (orders []*match.EncryptedAuctionOrder, err error) {

	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		err = fmt.Errorf("Error when beginning transaction for NewAuction: %s", err)
		return
	}

	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while placing puzzle order: \n%s", err)
			return
		}
		err = tx.Commit()
	}()

	// We don't really care about the result when trying to use a schema
	if _, err = tx.Exec("USE " + db.puzzleSchema + ";"); err != nil {
		err = fmt.Errorf("Error trying to use auction schema: %s", err)
		return
	}

	var rows *sql.Rows
	selectPuzzleQuery := fmt.Sprintf("SELECT encodedOrder FROM %s WHERE auctionID = '%x';", db.puzzleTable, auctionID)
	if rows, err = tx.Query(selectPuzzleQuery); err != nil {
		err = fmt.Errorf("Could not query for puzzles in viewauctionpuzzlebook: %s", err)
		return
	}

	var currEncryptedOrder *match.EncryptedAuctionOrder
	var encodedOrder []byte
	for rows.Next() {
		// allocate memory for the next order to be inserted in the list
		currEncryptedOrder = new(match.EncryptedAuctionOrder)

		if err = rows.Scan(&encodedOrder); err != nil {
			err = fmt.Errorf("Error scanning for puzzle: %s", err)
			return
		}

		// These are all encoded as hex in the db, so decode them
		if _, err = hex.Decode(encodedOrder, encodedOrder); err != nil {
			err = fmt.Errorf("Error decoding puzzle hex returned by database for viewing puzzle book: %s", err)
			return
		}

		if err = currEncryptedOrder.Deserialize(encodedOrder); err != nil {
			err = fmt.Errorf("Error deserializing order stored in db for viewing puzzle book: %s", err)
			return
		}

		// add the order to the list
		orders = append(orders, currEncryptedOrder)

	}

	return
}
// ViewAuctionPuzzleBook takes in an auction ID, and returns encrypted auction orders, and puzzles.
// You don't know what auction IDs should be in the orders encrypted in the puzzle book, but this is
// what was submitted.
ViewAuctionPuzzleBook takes in an auction ID, and returns encrypted auction orders, and puzzles.
You don't know what auction IDs should be in the orders encrypted in the puzzle book, but this is
what was submitted.
// ViewAuctionPuzzleBook takes in an auction ID and returns encrypted auction orders and puzzles . // You don ' t know what auction IDs should be in the orders encrypted in the puzzle book but this is // what was submitted .
func (db *DB) ViewAuctionPuzzleBook(auctionID [32]byte) (orders []*match.EncryptedAuctionOrder, err error) {
	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		err = fmt.Errorf("Error when beginning transaction for NewAuction: %s", err)
		return
	}
	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while placing puzzle order: \n%s", err)
			return
		}
		err = tx.Commit()
	}()
	if _, err = tx.Exec("USE " + db.puzzleSchema + ";"); err != nil {
		err = fmt.Errorf("Error trying to use auction schema: %s", err)
		return
	}
	var rows *sql.Rows
	selectPuzzleQuery := fmt.Sprintf("SELECT encodedOrder FROM %s WHERE auctionID = '%x';", db.puzzleTable, auctionID)
	if rows, err = tx.Query(selectPuzzleQuery); err != nil {
		err = fmt.Errorf("Could not query for puzzles in viewauctionpuzzlebook: %s", err)
		return
	}
	var currEncryptedOrder *match.EncryptedAuctionOrder
	var encodedOrder []byte
	for rows.Next() {
		currEncryptedOrder = new(match.EncryptedAuctionOrder)
		if err = rows.Scan(&encodedOrder); err != nil {
			err = fmt.Errorf("Error scanning for puzzle: %s", err)
			return
		}
		if _, err = hex.Decode(encodedOrder, encodedOrder); err != nil {
			err = fmt.Errorf("Error decoding puzzle hex returned by database for viewing puzzle book: %s", err)
			return
		}
		if err = currEncryptedOrder.Deserialize(encodedOrder); err != nil {
			err = fmt.Errorf("Error deserializing order stored in db for viewing puzzle book: %s", err)
			return
		}
		orders = append(orders, currEncryptedOrder)
	}
	return
}
func ( db * DB ) ViewAuctionPuzzleBook ( auctionID [ 32 ] byte ) ( orders [ ] * match . EncryptedAuctionOrder , err error ) { var tx * sql . Tx if tx , err = db . DBHandler . Begin ( ) ; err != nil { err = fmt . Errorf ( " " , err ) return } defer func ( ) { if err != nil { tx . Rollback ( ) err = fmt . Errorf ( " \n " , err ) return } err = tx . Commit ( ) } ( ) if _ , err = tx . Exec ( " " + db . puzzleSchema + " " ) ; err != nil { err = fmt . Errorf ( " " , err ) return } var rows * sql . Rows selectPuzzleQuery := fmt . Sprintf ( " " , db . puzzleTable , auctionID ) if rows , err = tx . Query ( selectPuzzleQuery ) ; err != nil { err = fmt . Errorf ( " " , err ) return } var currEncryptedOrder * match . EncryptedAuctionOrder var encodedOrder [ ] byte for rows . Next ( ) { currEncryptedOrder = new ( match . EncryptedAuctionOrder ) if err = rows . Scan ( & encodedOrder ) ; err != nil { err = fmt . Errorf ( " " , err ) return } if _ , err = hex . Decode ( encodedOrder , encodedOrder ) ; err != nil { err = fmt . Errorf ( " " , err ) return } if err = currEncryptedOrder . Deserialize ( encodedOrder ) ; err != nil { err = fmt . Errorf ( " " , err ) return } orders = append ( orders , currEncryptedOrder ) } return }
ViewAuctionPuzzleBook takes in an auction ID, and returns encrypted auction orders, and puzzles.
ViewAuctionPuzzleBook takes in an auction ID and returns encrypted auction orders and puzzles .
// We don't really care about the result when trying to use a schema // allocate memory for the next order to be inserted in the list // These are all encoded as hex in the db, so decode them // add the order to the list