Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for token Metadata 1.7.0 #12

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/metaplex-foundation/beet-swift",
"state" : {
"branch" : "1.0.4",
"revision" : "6c19f5c64f762f755070e108db4a486480cfe6a9"
"branch" : "1.0.7",
"revision" : "e4708bf28b55ce42727006c1cb7882f069d07bd8"
}
},
{
Expand Down
17 changes: 16 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ let package = Package(
.library(
name: "CandyMachine",
targets: ["CandyMachine"]
),
.library(
name: "TokenMetadata",
targets: ["TokenMetadata"]
)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/metaplex-foundation/beet-swift", branch: "1.0.4"),
.package(url: "https://github.com/metaplex-foundation/beet-swift", branch: "1.0.7"),
.package(url: "https://github.com/metaplex-foundation/solita-swift.git", branch: "1.0.3")
],
targets: [
Expand All @@ -40,6 +44,13 @@ let package = Package(
.product(name: "BeetSolana", package: "solita-swift")
]
),
.target(
name: "TokenMetadata",
dependencies: [
.product(name: "Beet", package: "beet-swift"),
.product(name: "BeetSolana", package: "solita-swift")
]
),
.testTarget(
name: "AuctionHouseTests",
dependencies: []
Expand All @@ -48,5 +59,9 @@ let package = Package(
name: "CandyMachineTests",
dependencies: []
),
.testTarget(
name: "TokenMetadataTests",
dependencies: []
),
]
)
20 changes: 20 additions & 0 deletions Sources/TokenMetadata/Program.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation
import Solana

/**
* Program address
*
* @category constants
* @category generated
*/

let PROGRAM_ADDRESS = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"

/**
* Program public key
*
* @category constants
* @category generated
*/

public let PROGRAM_ID = PublicKey(string: PROGRAM_ADDRESS)
144 changes: 144 additions & 0 deletions Sources/TokenMetadata/accounts/CollectionAuthorityRecord.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* This code was GENERATED using the solita package.
* Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality.
*
* See: https://github.com/metaplex-foundation/solita-swift
*/
import Foundation
import BeetSolana
import Solana
import Beet


/**
* Arguments used to create {@link Collectionauthorityrecord}
* @category Accounts
* @category generated
*/
public protocol CollectionauthorityrecordArgs {

var key: Key { get }
var bump: UInt8 { get }
var updateAuthority: COption<PublicKey> { get }
}

/**
* Holds the data for the {@link Collectionauthorityrecord} Account and provides de/serialization
* functionality for that data
*
* @category Accounts
* @category generated
*/
public struct Collectionauthorityrecord: CollectionauthorityrecordArgs {


public let key: Key
public let bump: UInt8
public let updateAuthority: COption<PublicKey>

/**
* Creates a {@link Collectionauthorityrecord} instance from the provided args.
*/
public static func fromArgs(args: Args) -> Collectionauthorityrecord {
return Collectionauthorityrecord(
key: args["key"] as! Key,
bump: args["bump"] as! UInt8,
updateAuthority: args["updateAuthority"] as! COption<PublicKey>
)
}
/**
* Deserializes the {@link Collectionauthorityrecord} from the data of the provided {@link web3.AccountInfo}.
* @returns a tuple of the account data and the offset up to which the buffer was read to obtain it.
*/
public static func fromAccountInfo(
accountInfo: Foundation.Data,
offset:Int=0
) -> ( Collectionauthorityrecord, Int ) {
return Collectionauthorityrecord.deserialize(buf: accountInfo, offset: offset)
}
/**
* Retrieves the account info from the provided address and deserializes
* the {@link Collectionauthorityrecord} from its data.
*
* @throws Error if no account info is found at the address or if deserialization fails
*/
public static func fromAccountAddress(
connection: Api,
address: PublicKey,
onComplete: @escaping (Result<Collectionauthorityrecord, Error>) -> Void
) {
connection.getAccountInfo(account: address.base58EncodedString) { result in
switch result {
case .success(let pureData):
if let data = pureData.data?.value {
onComplete(.success(Collectionauthorityrecord.deserialize(buf: data).0))
} else {
onComplete(.failure(SolanaError.nullValue))
}
case .failure(let error):
onComplete(.failure(error))
}
}
}
/**
* Deserializes the {@link Collectionauthorityrecord} from the provided data Buffer.
* @returns a tuple of the account data and the offset up to which the buffer was read to obtain it.
*/
public static func deserialize(
buf: Foundation.Data,
offset: Int = 0
) -> ( Collectionauthorityrecord, Int ) {
return collectionAuthorityRecordBeet.deserialize(buffer: buf, offset: offset)
}
/**
* Serializes the {@link Collectionauthorityrecord} into a Buffer.
* @returns a tuple of the created Buffer and the offset up to which the buffer was written to store it.
*/
public func serialize() -> ( Foundation.Data, Int ) {
return collectionAuthorityRecordBeet.serialize(instance: [
"key" : self.key,
"bump" : self.bump,
"updateAuthority" : self.updateAuthority
])
}
/**
* Returns the byteSize of a {@link Buffer} holding the serialized data of
* {@link Collectionauthorityrecord} for the provided args.
*
* @param args need to be provided since the byte size for this account
* depends on them
*/
static func byteSize(args: CollectionauthorityrecordArgs) -> UInt64 {
return UInt64(collectionAuthorityRecordBeet.toFixedFromValue(val: args).byteSize)
}
/**
* Fetches the minimum balance needed to exempt an account holding
* {@link Collectionauthorityrecord} data from rent
*
* @param args need to be provided since the byte size for this account
* depends on them
* @param connection used to retrieve the rent exemption information
*/
static func getMinimumBalanceForRentExemption(
args: CollectionauthorityrecordArgs,
connection: Api,
commitment: Commitment?,
onComplete: @escaping(Result<UInt64, Error>) -> Void
) {
return connection.getMinimumBalanceForRentExemption(dataLength: Collectionauthorityrecord.byteSize(args: args), commitment: commitment, onComplete: onComplete)
}
}
/**
* @category Accounts
* @category generated
*/
public let collectionAuthorityRecordBeet = FixableBeetStruct<Collectionauthorityrecord>(
fields:[

("key", keyBeetWrapped),
("bump", Beet.fixedBeet(.init(value: .scalar(u8())))),
("updateAuthority", Beet.fixableBeat(coption(inner: Beet.fixedBeet(.init(value: .scalar(BeetPublicKey()))))))
],
construct: Collectionauthorityrecord.fromArgs,
description: "Collectionauthorityrecord"
)
143 changes: 143 additions & 0 deletions Sources/TokenMetadata/accounts/Edition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/**
* This code was GENERATED using the solita package.
* Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality.
*
* See: https://github.com/metaplex-foundation/solita-swift
*/
import Foundation
import Beet
import BeetSolana
import Solana


/**
* Arguments used to create {@link Edition}
* @category Accounts
* @category generated
*/
public protocol EditionArgs {

var key: Key { get }
var parent: PublicKey { get }
var edition: UInt64 { get }
}

/**
* Holds the data for the {@link Edition} Account and provides de/serialization
* functionality for that data
*
* @category Accounts
* @category generated
*/
public struct Edition: EditionArgs {


public let key: Key
public let parent: PublicKey
public let edition: UInt64

/**
* Creates a {@link Edition} instance from the provided args.
*/
public static func fromArgs(args: Args) -> Edition {
return Edition(
key: args["key"] as! Key,
parent: args["parent"] as! PublicKey,
edition: args["edition"] as! UInt64
)
}
/**
* Deserializes the {@link Edition} from the data of the provided {@link web3.AccountInfo}.
* @returns a tuple of the account data and the offset up to which the buffer was read to obtain it.
*/
public static func fromAccountInfo(
accountInfo: Foundation.Data,
offset:Int=0
) -> ( Edition, Int ) {
return Edition.deserialize(buf: accountInfo, offset: offset)
}
/**
* Retrieves the account info from the provided address and deserializes
* the {@link Edition} from its data.
*
* @throws Error if no account info is found at the address or if deserialization fails
*/
public static func fromAccountAddress(
connection: Api,
address: PublicKey,
onComplete: @escaping (Result<Edition, Error>) -> Void
) {
connection.getAccountInfo(account: address.base58EncodedString) { result in
switch result {
case .success(let pureData):
if let data = pureData.data?.value {
onComplete(.success(Edition.deserialize(buf: data).0))
} else {
onComplete(.failure(SolanaError.nullValue))
}
case .failure(let error):
onComplete(.failure(error))
}
}
}
/**
* Deserializes the {@link Edition} from the provided data Buffer.
* @returns a tuple of the account data and the offset up to which the buffer was read to obtain it.
*/
public static func deserialize(
buf: Foundation.Data,
offset: Int = 0
) -> ( Edition, Int ) {
return editionBeet.deserialize(buffer: buf, offset: offset)
}
/**
* Serializes the {@link Edition} into a Buffer.
* @returns a tuple of the created Buffer and the offset up to which the buffer was written to store it.
*/
public func serialize() -> ( Foundation.Data, Int ) {
return editionBeet.serialize(instance: Edition(key : self.key,
parent : self.parent,
edition : self.edition))
}
/**
* Returns the byteSize of a {@link Buffer} holding the serialized data of
* {@link Edition}
*/
static func byteSize() -> UInt {
return editionBeet.byteSize
}
/**
* Fetches the minimum balance needed to exempt an account holding
* {@link Edition} data from rent
*
* @param connection used to retrieve the rent exemption information
*/
static func getMinimumBalanceForRentExemption(
connection: Api,
commitment: Commitment?,
onComplete: @escaping(Result<UInt64, Error>) -> Void
) {
return connection.getMinimumBalanceForRentExemption(dataLength: UInt64(Edition.byteSize()), commitment: commitment, onComplete: onComplete)
}
/**
* Determines if the provided {@link Buffer} has the correct byte size to
* hold {@link Edition} data.
*/
static func hasCorrectByteSize(buf: Foundation.Data, offset:Int=0) -> Bool {
return buf.bytes.count - offset == Edition.byteSize()
}
}
/**
* @category Accounts
* @category generated
*/
public let editionBeet = BeetStruct(
fields:[

("key", keyBeet),
("parent", (.init(value: .scalar(BeetPublicKey())))),
("edition", (.init(value: .scalar(u64()))))
],
construct: Edition.fromArgs,
description: "Edition"
)