Compare commits

...

8 Commits

Author SHA1 Message Date
ledhed2222
9c4f2f4924 Merge branch 'develop' into 2.1.0 2021-11-19 16:45:57 -05:00
Greg Weisbrod
b18af1b8c4 make a beta 2.1.0 2021-11-19 16:42:31 -05:00
Greg Weisbrod
1320fb03fa add requests and responses 2021-11-19 16:40:54 -05:00
Greg Weisbrod
e5cac8aa35 add NFTokenAcceptOffer 2021-11-19 16:40:44 -05:00
Greg Weisbrod
1d38ec497b add NFTokenCancelOffer 2021-11-19 16:40:39 -05:00
Greg Weisbrod
693110532b add NFTokenCreateOffer 2021-11-19 16:40:32 -05:00
Greg Weisbrod
a1c5c82645 add NFTokenBurn and NFTokenMint 2021-11-19 16:40:20 -05:00
Greg Weisbrod
0de4a9625f Merge branch 'develop' of https://github.com/XRPLF/xrpl.js into develop 2021-11-16 00:56:05 -05:00
13 changed files with 649 additions and 3028 deletions

3046
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
import { BaseRequest, BaseResponse } from './baseMethod'
/**
* The `account_nfts` method retrieves all of the NFTs currently owned by the
* specified account.
*
* @category Requests
*/
export interface AccountNFTsRequest extends BaseRequest {
command: 'account_nfts'
/**
* The unique identifier of an account, typically the account's address. The
* request returns NFTs owned by this account.
*/
account: string
/**
* Limit the number of NFTokens to retrieve.
*/
limit?: number
/**
* Value from a previous paginated response. Resume retrieving data where
* that response left off.
*/
marker?: unknown
}
/**
* One NFToken that might be returned from an {@link AccountNFTsRequest}.
*
* @category Responses
*/
interface AccountNFToken {
// TODO Need to check all this
Flags: number
Issuer: string
TokenID: string
TokenTaxons: number
nft_serial: number
}
/**
* Response expected from an {@link AccountNFTsRequest}.
*
* @category Responses
*/
export interface AccountNFTsResponse extends BaseResponse {
result: {
/**
* A list of NFTs owned by the specified account.
*/
account_nfts: AccountNFToken[]
/**
* The ledger index of the current open ledger, which was used when
* retrieving this information.
*/
ledger_current_index: number
/** If true, this data comes from a validated ledger. */
validated: boolean
/**
* Server-defined value indicating the response is paginated. Pass this to
* the next call to resume where this call left off. Omitted when there are
* No additional pages after this one.
*/
marker?: unknown
/** The limit that was used to fulfill this request. */
limit?: number
}
}

View File

@@ -8,6 +8,7 @@ import {
} from './accountCurrencies'
import { AccountInfoRequest, AccountInfoResponse } from './accountInfo'
import { AccountLinesRequest, AccountLinesResponse } from './accountLines'
import { AccountNFTsRequest, AccountNFTsResponse } from './accountNFTs'
import { AccountObjectsRequest, AccountObjectsResponse } from './accountObjects'
import { AccountOffersRequest, AccountOffersResponse } from './accountOffers'
import { AccountTxRequest, AccountTxResponse } from './accountTx'
@@ -29,6 +30,8 @@ import { LedgerCurrentRequest, LedgerCurrentResponse } from './ledgerCurrent'
import { LedgerDataRequest, LedgerDataResponse } from './ledgerData'
import { LedgerEntryRequest, LedgerEntryResponse } from './ledgerEntry'
import { ManifestRequest, ManifestResponse } from './manifest'
import { NFTBuyOffersRequest, NFTBuyOffersResponse } from './nftBuyOffers'
import { NFTSellOffersRequest, NFTSellOffersResponse } from './nftSellOffers'
import { NoRippleCheckRequest, NoRippleCheckResponse } from './norippleCheck'
import {
PathFindRequest,
@@ -70,10 +73,12 @@ import { UnsubscribeRequest, UnsubscribeResponse } from './unsubscribe'
* @category Requests
*/
type Request =
// account methods
| AccountChannelsRequest
| AccountCurrenciesRequest
| AccountInfoRequest
| AccountLinesRequest
| AccountNFTsRequest
| AccountObjectsRequest
| AccountOffersRequest
| AccountTxRequest
@@ -108,15 +113,20 @@ type Request =
// utility methods
| PingRequest
| RandomRequest
// NFT methods
| NFTBuyOffersRequest
| NFTSellOffersRequest
/**
* @category Responses
*/
type Response =
// account methods
| AccountChannelsResponse
| AccountCurrenciesResponse
| AccountInfoResponse
| AccountLinesResponse
| AccountNFTsResponse
| AccountObjectsResponse
| AccountOffersResponse
| AccountTxResponse
@@ -151,6 +161,9 @@ type Response =
// utility methods
| PingResponse
| RandomResponse
// NFT methods
| NFTBuyOffersResponse
| NFTSellOffersResponse
export {
Request,
@@ -164,6 +177,8 @@ export {
AccountInfoResponse,
AccountLinesRequest,
AccountLinesResponse,
AccountNFTsRequest,
AccountNFTsResponse,
AccountObjectsRequest,
AccountObjectsResponse,
AccountOffersRequest,
@@ -238,4 +253,9 @@ export {
RandomRequest,
RandomResponse,
ErrorResponse,
// NFT methods
NFTBuyOffersRequest,
NFTBuyOffersResponse,
NFTSellOffersRequest,
NFTSellOffersResponse,
}

View File

@@ -0,0 +1,50 @@
import { Amount } from '../common'
import { BaseRequest, BaseResponse } from './baseMethod'
/**
* The `nft_buy_offers` method retrieves all of buy offers for the specified
* NFToken.
*
* @category Requests
*/
export interface NFTBuyOffersRequest extends BaseRequest {
command: 'nft_buy_offers'
/**
* The unique identifier of an NFToken. The request returns buy offers for this NFToken.
*/
tokenid: string
}
/**
* One buy offer that might be returned from an {@link NFTBuyOffersRequest}.
*
* @category Responses
*/
interface NFTBuyOffer {
// TODO Need to check all this
amount: Amount
destination: string
expiration: number
flags: number
index: string
owner: string
}
/**
* Response expected from an {@link NFTBuyOffersRequest}.
*
* @category Responses
*/
export interface NFTBuyOffersResponse extends BaseResponse {
result: {
/**
* A list of buy offers for the specified NFToken.
*/
offers: NFTBuyOffer[]
/**
* The token ID of the NFToken to which these offers pertain.
*/
tokenid: string
}
}

View File

@@ -0,0 +1,50 @@
import { Amount } from '../common'
import { BaseRequest, BaseResponse } from './baseMethod'
/**
* The `nft_sell_offers` method retrieves all of sell offers for the specified
* NFToken.
*
* @category Requests
*/
export interface NFTSellOffersRequest extends BaseRequest {
command: 'nft_sell_offers'
/**
* The unique identifier of an NFToken. The request returns sell offers for this NFToken.
*/
tokenid: string
}
/**
* One sell offer that might be returned from an {@link NFTSellOffersRequest}.
*
* @category Responses
*/
interface NFTSellOffer {
// TODO Need to check all this
amount: Amount
destination: string
expiration: number
flags: number
index: string
owner: string
}
/**
* Response expected from an {@link NFTSellOffersRequest}.
*
* @category Responses
*/
export interface NFTSellOffersResponse extends BaseResponse {
result: {
/**
* A list of sell offers for the specified NFToken.
*/
offers: NFTSellOffer[]
/**
* The token ID of the NFToken to which these offers pertain.
*/
tokenid: string
}
}

View File

@@ -0,0 +1,80 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
import { BaseTransaction, validateBaseTransaction, isAmount } from './common'
/**
* The NFTokenAcceptOffer transaction creates an NFToken object and adds it to the
* relevant NFTokenPage object of the minter. If the transaction is
* successful, the newly minted token will be owned by the minter account
* specified by the transaction.
*/
export interface NFTokenAcceptOffer extends BaseTransaction {
TransactionType: 'NFTokenAcceptOffer'
/**
* Identifies the NFTokenOffer that offers to sell the NFToken.
*
* In direct mode this field is optional, but either SellOffer or
* BuyOffer must be specified. In brokered mode, both SellOffer
* and BuyOffer MUST be specified.
*/
SellOffer?: string
/**
* Identifies the NFTokenOffer that offers to buy the NFToken.
*
* In direct mode this field is optional, but either SellOffer or
* BuyOffer must be specified. In brokered mode, both SellOffer
* and BuyOffer MUST be specified.
*/
BuyOffer?: string
/**
* This field is only valid in brokered mode and specifies the
* amount that the broker will keep as part of their fee for
* bringing the two offers together; the remaining amount will
* be sent to the seller of the NFToken being bought. If
* specified, the fee must be such that, prior to accounting
* for the transfer fee charged by the issuer, the amount that
* the seller would receive is at least as much as the amount
* indicated in the sell offer.
*
* This functionality is intended to allow the owner of an
* NFToken to offer their token for sale to a third party
* broker, who may then attempt to sell the NFToken on for a
* larger amount, without the broker having to own the NFToken
* or custody funds.
*
* If both offers are for the same asset, it is possible that
* the order in which funds are transferred might cause a
* transaction that would succeed to fail due to an apparent
* lack of funds. To ensure deterministic transaction execution
* and maximimize the chances of successful execution, this
* proposal requires that the account attempting to buy the
* NFToken is debited first and that funds due to the broker
* are credited before crediting the seller.
*
* Note: in brokered mode, The offers referenced by BuyOffer
* and SellOffer must both specify the same TokenID; that is,
* both must be for the same NFToken.
*/
BrokerFee?: Amount
}
/**
* Verify the form and type of an NFTokenAcceptOffer at runtime.
*
* @param tx - An NFTokenAcceptOffer Transaction.
* @throws When the NFTokenAcceptOffer is Malformed.
*/
export function validateNFTokenAcceptOffer(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (
tx.BrokerFee != null &&
typeof tx.BrokerFee !== 'string' &&
!isAmount(tx.BrokerFee)
) {
throw new ValidationError('NFTokenAcceptOffer: invalid BrokerFee')
}
// TODO more validations
}

View File

@@ -0,0 +1,46 @@
import { ValidationError } from '../../errors'
import { BaseTransaction, validateBaseTransaction } from './common'
/**
* The NFTokenBurn transaction is used to remove an NFToken object from the
* NFTokenPage in which it is being held, effectively removing the token from
* the ledger ("burning" it).
*
* If this operation succeeds, the corresponding NFToken is removed. If this
* operation empties the NFTokenPage holding the NFToken or results in the
* consolidation, thus removing an NFTokenPage, the owners reserve requirement
* is reduced by one.
*/
export interface NFTokenBurn extends BaseTransaction {
TransactionType: 'NFTokenBurn'
/**
* Indicates the AccountID that submitted this transaction. The account MUST
* be either the present owner of the token or, if the lsfBurnable flag is set
* in the NFToken, either the issuer account or an account authorized by the
* issuer, i.e. MintAccount.
*/
Account: string
/**
* Identifies the NFToken object to be removed by the transaction.
*/
TokenID: string
}
/**
* Verify the form and type of an NFTokenBurn at runtime.
*
* @param tx - An NFTokenBurn Transaction.
* @throws When the NFTokenBurn is Malformed.
*/
export function validateNFTokenBurn(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Account == null) {
throw new ValidationError('NFTokenBurn: missing field Account')
}
if (tx.TokenID == null) {
throw new ValidationError('NFTokenBurn: missing field TokenID')
}
}

View File

@@ -0,0 +1,38 @@
import { ValidationError } from '../../errors'
import { BaseTransaction, validateBaseTransaction } from './common'
/**
* The NFTokenCancelOffer transaction creates an NFToken object and adds it to the
* relevant NFTokenPage object of the minter. If the transaction is
* successful, the newly minted token will be owned by the minter account
* specified by the transaction.
*/
export interface NFTokenCancelOffer extends BaseTransaction {
TransactionType: 'NFTokenCancelOffer'
/**
* An array of TokenID objects, each identifying an
* NFTokenOffer object, which should be cancelled by this
* transaction.
*
* It is an error if an entry in this list points to an
* object that is not an NFTokenOffer object. It is not an
* error if an entry in this list points to an object that
* does not exist.
*/
TokenIDs: string[]
}
/**
* Verify the form and type of an NFTokenCancelOffer at runtime.
*
* @param tx - An NFTokenCancelOffer Transaction.
* @throws When the NFTokenCancelOffer is Malformed.
*/
export function validateNFTokenCancelOffer(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (!Array.isArray(tx.TokenIDs) || tx.TokenIDs.length < 1) {
throw new ValidationError('NFTokenCancelOffer: missing field TokenIDs')
}
}

View File

@@ -0,0 +1,116 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
import {
BaseTransaction,
GlobalFlags,
validateBaseTransaction,
isAmount,
} from './common'
/**
* Transaction Flags for an NFTokenCreateOffer Transaction.
*
* @category Transaction Flags
*/
export enum NFTokenCreateOfferFlags {
/**
* If set, indicates that the offer is a sell offer.
* Otherwise, it is a buy offer.
*/
tfSellToken = 0x00000001,
}
/**
* Map of flags to boolean values representing {@link NFTokenCreateOffer} transaction
* flags.
*
* @category Transaction Flags
*/
export interface NFTokenCreateOfferFlagsInterface extends GlobalFlags {
tfSellToken?: boolean
}
/**
* The NFTokenCreateOffer transaction creates an NFToken object and adds it to the
* relevant NFTokenPage object of the minter. If the transaction is
* successful, the newly minted token will be owned by the minter account
* specified by the transaction.
*/
export interface NFTokenCreateOffer extends BaseTransaction {
TransactionType: 'NFTokenCreateOffer'
/**
* Indicates the AccountID of the account that initiated the
* transaction.
*/
Account: string
/**
* Identifies the TokenID of the NFToken object that the
* offer references.
*/
TokenID: string
/**
* Indicates the amount expected or offered for the Token.
*
* The amount must be non-zero, except where this is an
* offer is an offer to sell and the asset is XRP; then it
* is legal to specify an amount of zero, which means that
* the current owner of the token is giving it away, gratis,
* either to anyone at all, or to the account identified by
* the Destination field.
*/
Amount: Amount
/**
* Indicates the AccountID of the account that owns the
* corresponding NFToken.
*
* If the offer is to buy a token, this field must be present
* and it must be different than Account (since an offer to
* buy a token one already holds is meaningless).
*
* If the offer is to sell a token, this field must not be
* present, as the owner is, implicitly, the same as Account
* (since an offer to sell a token one doesn't already hold
* is meaningless).
*/
Owner?: string
/**
* Indicates the time after which the offer will no longer
* be valid. The value is the number of seconds since the
* Ripple Epoch.
*/
Expiration?: number
/**
* If present, indicates that this offer may only be
* accepted by the specified account. Attempts by other
* accounts to accept this offer MUST fail.
*/
Destination?: string
Flags?: number | NFTokenCreateOfferFlagsInterface
}
/**
* Verify the form and type of an NFTokenCreateOffer at runtime.
*
* @param tx - An NFTokenCreateOffer Transaction.
* @throws When the NFTokenCreateOffer is Malformed.
*/
export function validateNFTokenCreateOffer(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Account == null) {
throw new ValidationError('NFTokenCreateOffer: missing field Account')
}
if (tx.TokenID == null) {
throw new ValidationError('NFTokenCreateOffer: missing field TokenID')
}
if (tx.Amount == null) {
throw new ValidationError('NFTokenCreateOffer: missing field Amount')
}
if (typeof tx.Amount !== 'string' && !isAmount(tx.Amount)) {
throw new ValidationError('NFTokenCreateOffer: invalid Amount')
}
}

View File

@@ -0,0 +1,105 @@
import { ValidationError } from '../../errors'
import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
/**
* Transaction Flags for an NFTokenMint Transaction.
*
* @category Transaction Flags
*/
export enum NFTokenMintFlags {
/**
* If set, indicates that the minted token may be burned by the issuer even
* if the issuer does not currently hold the token. The current holder of
* the token may always burn it.
*/
tfBurnable = 0x00000001,
/**
* If set, indicates that the token may only be offered or sold for XRP.
*/
tfOnlyXRP = 0x00000002,
/**
* If set, indicates that the issuer wants a trustline to be automatically
* created.
*/
tfTrustLine = 0x00000004,
/**
* If set, indicates that this NFT can be transferred. This flag has no
* effect if the token is being transferred from the issuer or to the
* issuer.
*/
tfTransferable = 0x00000008,
}
/**
* Map of flags to boolean values representing {@link NFTokenMint} transaction
* flags.
*
* @category Transaction Flags
*/
export interface NFTokenMintFlagsInterface extends GlobalFlags {
tfBurnable?: boolean
tfOnlyXRP?: boolean
tfTrustLine?: boolean
tfTransferable?: boolean
}
/**
* The NFTokenMint transaction creates an NFToken object and adds it to the
* relevant NFTokenPage object of the minter. If the transaction is
* successful, the newly minted token will be owned by the minter account
* specified by the transaction.
*/
export interface NFTokenMint extends BaseTransaction {
TransactionType: 'NFTokenMint'
/**
* Indicates the taxon associated with this token. The taxon is generally a
* value chosen by the minter of the token and a given taxon may be used for
* multiple tokens. The implementation reserves taxon identifiers greater
* than or equal to 2147483648 (0x80000000).
*/
TokenTaxon: number
/**
* Indicates the account that should be the issuer of this token. This value
* is optional and should only be specified if the account executing the
* transaction is not the `Issuer` of the `NFToken` object. If it is
* present, the `MintAccount` field in the `AccountRoot` of the `Issuer`
* field must match the `Account`, otherwise the transaction will fail.
*/
Issuer?: string
/**
* Specifies the fee charged by the issuer for secondary sales of the Token,
* if such sales are allowed. Valid values for this field are between 0 and
* 50000 inclusive, allowing transfer rates between 0.000% and 50.000% in
* increments of 0.001%. This field must NOT be present if the
* `tfTransferable` flag is not set.
*/
TransferFee?: number
/**
* URI that points to the data and/or metadata associated with the NFT.
* This field need not be an HTTP or HTTPS URL; it could be an IPFS URI, a
* magnet link, immediate data encoded as an RFC2379 "data" URL, or even an
* opaque issuer-specific encoding. The URI is NOT checked for validity, but
* the field is limited to a maximum length of 256 bytes.
*/
URI?: string
Flags?: number | NFTokenMintFlagsInterface
}
/**
* Verify the form and type of an NFTokenMint at runtime.
*
* @param tx - An NFTokenMint Transaction.
* @throws When the NFTokenMint is Malformed.
*/
export function validateNFTokenMint(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Account == null) {
throw new ValidationError('NFTokenMint: missing field Account')
}
if (tx.TokenTaxon == null) {
throw new ValidationError('NFTokenMint: missing field TokenTaxon')
}
}

View File

@@ -135,6 +135,12 @@ export interface AccountSet extends BaseTransaction {
* digits. Valid values are 3 to 15 inclusive, or 0 to disable.
*/
TickSize?: number
/**
* TODO check
* Sets an alternate account that is allowed to mint NFTokens on this
* account's behalf using NFTokenMint's `Issuer` field.
*/
Minter?: string
}
const MIN_TICK_SIZE = 3

View File

@@ -14,6 +14,19 @@ export { DepositPreauth } from './depositPreauth'
export { EscrowCancel } from './escrowCancel'
export { EscrowCreate } from './escrowCreate'
export { EscrowFinish } from './escrowFinish'
export { NFTokenAcceptOffer } from './NFTokenAcceptOffer'
export { NFTokenBurn } from './NFTokenBurn'
export { NFTokenCancelOffer } from './NFTokenCancelOffer'
export {
NFTokenCreateOffer,
NFTokenCreateOfferFlags,
NFTokenCreateOfferFlagsInterface,
} from './NFTokenCreateOffer'
export {
NFTokenMint,
NFTokenMintFlags,
NFTokenMintFlagsInterface,
} from './NFTokenMint'
export { OfferCancel } from './offerCancel'
export {
OfferCreateFlags,

View File

@@ -17,6 +17,20 @@ import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
import { EscrowFinish, validateEscrowFinish } from './escrowFinish'
import { TransactionMetadata } from './metadata'
import {
NFTokenAcceptOffer,
validateNFTokenAcceptOffer,
} from './NFTokenAcceptOffer'
import { NFTokenBurn, validateNFTokenBurn } from './NFTokenBurn'
import {
NFTokenCancelOffer,
validateNFTokenCancelOffer,
} from './NFTokenCancelOffer'
import {
NFTokenCreateOffer,
validateNFTokenCreateOffer,
} from './NFTokenCreateOffer'
import { NFTokenMint, validateNFTokenMint } from './NFTokenMint'
import { OfferCancel, validateOfferCancel } from './offerCancel'
import { OfferCreate, validateOfferCreate } from './offerCreate'
import { Payment, validatePayment } from './payment'
@@ -50,6 +64,11 @@ export type Transaction =
| EscrowCancel
| EscrowCreate
| EscrowFinish
| NFTokenAcceptOffer
| NFTokenBurn
| NFTokenCancelOffer
| NFTokenCreateOffer
| NFTokenMint
| OfferCancel
| OfferCreate
| Payment
@@ -124,6 +143,26 @@ export function validate(transaction: Record<string, unknown>): void {
validateEscrowFinish(tx)
break
case 'NFTokenAcceptOffer':
validateNFTokenAcceptOffer(tx)
break
case 'NFTokenBurn':
validateNFTokenBurn(tx)
break
case 'NFTokenCancelOffer':
validateNFTokenCancelOffer(tx)
break
case 'NFTokenCreateOffer':
validateNFTokenCreateOffer(tx)
break
case 'NFTokenMint':
validateNFTokenMint(tx)
break
case 'OfferCancel':
validateOfferCancel(tx)
break