mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-07 06:15:49 +00:00
Compare commits
3 Commits
@transia/r
...
denis-urit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7efc525fa2 | ||
|
|
f3ec0f654e | ||
|
|
4b63c2bd95 |
@@ -44,6 +44,7 @@
|
|||||||
"NegativeUNL": 78,
|
"NegativeUNL": 78,
|
||||||
"NFTokenPage": 80,
|
"NFTokenPage": 80,
|
||||||
"NFTokenOffer": 55,
|
"NFTokenOffer": 55,
|
||||||
|
"URIToken": 85,
|
||||||
"Any": -3,
|
"Any": -3,
|
||||||
"Child": -2,
|
"Child": -2,
|
||||||
"Nickname": 110,
|
"Nickname": 110,
|
||||||
@@ -1281,6 +1282,16 @@
|
|||||||
"type": "Hash256"
|
"type": "Hash256"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"URITokenID",
|
||||||
|
{
|
||||||
|
"nth": 36,
|
||||||
|
"isVLEncoded": false,
|
||||||
|
"isSerialized": true,
|
||||||
|
"isSigningField": true,
|
||||||
|
"type": "Hash256"
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"Amount",
|
"Amount",
|
||||||
{
|
{
|
||||||
@@ -2330,6 +2341,11 @@
|
|||||||
"NFTokenCreateOffer": 27,
|
"NFTokenCreateOffer": 27,
|
||||||
"NFTokenCancelOffer": 28,
|
"NFTokenCancelOffer": 28,
|
||||||
"NFTokenAcceptOffer": 29,
|
"NFTokenAcceptOffer": 29,
|
||||||
|
"URITokenMint": 45,
|
||||||
|
"URITokenBurn": 46,
|
||||||
|
"URITokenBuy": 47,
|
||||||
|
"URITokenCreateSellOffer": 48,
|
||||||
|
"URITokenCancelSellOffer": 49,
|
||||||
"EnableAmendment": 100,
|
"EnableAmendment": 100,
|
||||||
"SetFee": 101,
|
"SetFee": 101,
|
||||||
"UNLModify": 102
|
"UNLModify": 102
|
||||||
|
|||||||
@@ -45,3 +45,12 @@ export { SetRegularKey } from './setRegularKey'
|
|||||||
export { SignerListSet } from './signerListSet'
|
export { SignerListSet } from './signerListSet'
|
||||||
export { TicketCreate } from './ticketCreate'
|
export { TicketCreate } from './ticketCreate'
|
||||||
export { TrustSetFlagsInterface, TrustSetFlags, TrustSet } from './trustSet'
|
export { TrustSetFlagsInterface, TrustSetFlags, TrustSet } from './trustSet'
|
||||||
|
export {
|
||||||
|
URITokenMintFlagsInterface,
|
||||||
|
URITokenMintFlags,
|
||||||
|
URITokenMint,
|
||||||
|
} from './uriTokenMint'
|
||||||
|
export { URITokenBurn } from './uriTokenBurn'
|
||||||
|
export { URITokenSell } from './uriTokenSell'
|
||||||
|
export { URITokenBuy } from './uriTokenBuy'
|
||||||
|
export { URITokenClear } from './uriTokenClear'
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
|
|||||||
import { SignerListSet, validateSignerListSet } from './signerListSet'
|
import { SignerListSet, validateSignerListSet } from './signerListSet'
|
||||||
import { TicketCreate, validateTicketCreate } from './ticketCreate'
|
import { TicketCreate, validateTicketCreate } from './ticketCreate'
|
||||||
import { TrustSet, validateTrustSet } from './trustSet'
|
import { TrustSet, validateTrustSet } from './trustSet'
|
||||||
|
import { URITokenBurn, validateURITokenBurn } from './uriTokenBurn'
|
||||||
|
import { URITokenBuy, validateURITokenBuy } from './uriTokenBuy'
|
||||||
|
import { URITokenClear, validateURITokenClear } from './uriTokenClear'
|
||||||
|
import { URITokenMint, validateURITokenMint } from './uriTokenMint'
|
||||||
|
import { URITokenSell, validateURITokenSell } from './uriTokenSell'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @category Transaction Models
|
* @category Transaction Models
|
||||||
@@ -80,6 +85,11 @@ export type Transaction =
|
|||||||
| SignerListSet
|
| SignerListSet
|
||||||
| TicketCreate
|
| TicketCreate
|
||||||
| TrustSet
|
| TrustSet
|
||||||
|
| URITokenBurn
|
||||||
|
| URITokenBuy
|
||||||
|
| URITokenClear
|
||||||
|
| URITokenMint
|
||||||
|
| URITokenSell
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @category Transaction Models
|
* @category Transaction Models
|
||||||
@@ -204,6 +214,26 @@ export function validate(transaction: Record<string, unknown>): void {
|
|||||||
validateTrustSet(tx)
|
validateTrustSet(tx)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case 'URITokenMint':
|
||||||
|
validateURITokenMint(tx)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'URITokenBurn':
|
||||||
|
validateURITokenBurn(tx)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'URITokenCreateSellOffer':
|
||||||
|
validateURITokenSell(tx)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'URITokenBuy':
|
||||||
|
validateURITokenBuy(tx)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'URITokenCancelSellOffer':
|
||||||
|
validateURITokenClear(tx)
|
||||||
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ValidationError(
|
throw new ValidationError(
|
||||||
`Invalid field TransactionType: ${tx.TransactionType}`,
|
`Invalid field TransactionType: ${tx.TransactionType}`,
|
||||||
|
|||||||
60
packages/xrpl/src/models/transactions/uriTokenBurn.ts
Normal file
60
packages/xrpl/src/models/transactions/uriTokenBurn.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { ValidationError } from '../../errors'
|
||||||
|
|
||||||
|
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of flags to boolean values representing {@link URITokenBurn} transaction
|
||||||
|
* flags.
|
||||||
|
*
|
||||||
|
* @category Transaction Flags
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const tx: URITokenBurn = {
|
||||||
|
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
|
||||||
|
* TransactionType: 'URITokenBurn',
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // Autofill the tx to see how flags actually look compared to the interface usage.
|
||||||
|
* const autofilledTx = await client.autofill(tx)
|
||||||
|
* console.log(autofilledTx)
|
||||||
|
* // {
|
||||||
|
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
|
||||||
|
* // TransactionType: 'URITokenBurn',
|
||||||
|
* // Sequence: 21970384,
|
||||||
|
* // Fee: '12',
|
||||||
|
* // LastLedgerSequence: 21970404
|
||||||
|
* // }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An URITokenBurn transaction is effectively a limit order . It defines an
|
||||||
|
* intent to exchange currencies, and creates an Offer object if not completely.
|
||||||
|
* Fulfilled when placed. Offers can be partially fulfilled.
|
||||||
|
*
|
||||||
|
* @category Transaction Models
|
||||||
|
*/
|
||||||
|
export interface URITokenBurn extends BaseTransaction {
|
||||||
|
TransactionType: 'URITokenBurn'
|
||||||
|
/**
|
||||||
|
* Identifies the URIToken object to be removed by the transaction.
|
||||||
|
*/
|
||||||
|
URITokenID: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an URITokenBurn at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An URITokenBurn Transaction.
|
||||||
|
* @throws When the URITokenBurn is Malformed.
|
||||||
|
*/
|
||||||
|
export function validateURITokenBurn(tx: Record<string, unknown>): void {
|
||||||
|
validateBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.URITokenID == null) {
|
||||||
|
throw new ValidationError('NFTokenBurn: missing field URITokenID')
|
||||||
|
}
|
||||||
|
}
|
||||||
83
packages/xrpl/src/models/transactions/uriTokenBuy.ts
Normal file
83
packages/xrpl/src/models/transactions/uriTokenBuy.ts
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import { ValidationError } from '../../errors'
|
||||||
|
import { Amount } from '../common'
|
||||||
|
|
||||||
|
import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of flags to boolean values representing {@link URITokenBuy} transaction
|
||||||
|
* flags.
|
||||||
|
*
|
||||||
|
* @category Transaction Flags
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const tx: URITokenBuy = {
|
||||||
|
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
|
||||||
|
* Amount: '1000000',
|
||||||
|
* TransactionType: 'URITokenBuy',
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // Autofill the tx to see how flags actually look compared to the interface usage.
|
||||||
|
* const autofilledTx = await client.autofill(tx)
|
||||||
|
* console.log(autofilledTx)
|
||||||
|
* // {
|
||||||
|
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
|
||||||
|
* // Amount: '1000000',
|
||||||
|
* // TransactionType: 'URITokenBuy',
|
||||||
|
* // Sequence: 21970384,
|
||||||
|
* // Fee: '12',
|
||||||
|
* // LastLedgerSequence: 21970404
|
||||||
|
* // }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An URITokenBuy transaction is effectively a limit order . It defines an
|
||||||
|
* intent to exchange currencies, and creates an Offer object if not completely.
|
||||||
|
* Fulfilled when placed. Offers can be partially fulfilled.
|
||||||
|
*
|
||||||
|
* @category Transaction Models
|
||||||
|
*/
|
||||||
|
export interface URITokenBuy extends BaseTransaction {
|
||||||
|
TransactionType: 'URITokenBuy'
|
||||||
|
/**
|
||||||
|
* Identifies the URITokenID of the NFToken object that the
|
||||||
|
* offer references.
|
||||||
|
*/
|
||||||
|
URITokenID: string
|
||||||
|
/**
|
||||||
|
* Indicates the amount expected or offered for the Token.
|
||||||
|
*
|
||||||
|
* The amount must be non-zero, except when this is a sell
|
||||||
|
* offer and the asset is XRP. This would indicate that the current
|
||||||
|
* owner of the token is giving it away free, either to anyone at all,
|
||||||
|
* or to the account identified by the Destination field.
|
||||||
|
*/
|
||||||
|
Amount: Amount
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an URITokenBuy at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An URITokenBuy Transaction.
|
||||||
|
* @throws When the URITokenBuy is Malformed.
|
||||||
|
*/
|
||||||
|
export function validateURITokenBuy(tx: Record<string, unknown>): void {
|
||||||
|
validateBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.Account === tx.Destination) {
|
||||||
|
throw new ValidationError(
|
||||||
|
'URITokenBuy: Destination and Account must not be equal',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx.URITokenID == null) {
|
||||||
|
throw new ValidationError('URITokenBuy: missing field URITokenID')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAmount(tx.Amount)) {
|
||||||
|
throw new ValidationError('URITokenBuy: invalid Amount')
|
||||||
|
}
|
||||||
|
}
|
||||||
61
packages/xrpl/src/models/transactions/uriTokenClear.ts
Normal file
61
packages/xrpl/src/models/transactions/uriTokenClear.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { ValidationError } from '../../errors'
|
||||||
|
|
||||||
|
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of flags to boolean values representing {@link URITokenClear} transaction
|
||||||
|
* flags.
|
||||||
|
*
|
||||||
|
* @category Transaction Flags
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const tx: URITokenClear = {
|
||||||
|
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
|
||||||
|
* TransactionType: 'URITokenCancelSellOffer',
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // Autofill the tx to see how flags actually look compared to the interface usage.
|
||||||
|
* const autofilledTx = await client.autofill(tx)
|
||||||
|
* console.log(autofilledTx)
|
||||||
|
* // {
|
||||||
|
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
|
||||||
|
* // TransactionType: 'URITokenCancelSellOffer',
|
||||||
|
* // Sequence: 21970384,
|
||||||
|
* // Fee: '12',
|
||||||
|
* // LastLedgerSequence: 21970404
|
||||||
|
* // }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An URITokenClear transaction is effectively a limit order . It defines an
|
||||||
|
* intent to exchange currencies, and creates an Offer object if not completely.
|
||||||
|
* Fulfilled when placed. Offers can be partially fulfilled.
|
||||||
|
*
|
||||||
|
* @category Transaction Models
|
||||||
|
*/
|
||||||
|
export interface URITokenClear extends BaseTransaction {
|
||||||
|
TransactionType: 'URITokenCancelSellOffer'
|
||||||
|
/**
|
||||||
|
* Identifies the URITokenID of the NFToken object that the
|
||||||
|
* offer references.
|
||||||
|
*/
|
||||||
|
URITokenID: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an URITokenClear at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An URITokenClear Transaction.
|
||||||
|
* @throws When the URITokenClear is Malformed.
|
||||||
|
*/
|
||||||
|
export function validateURITokenClear(tx: Record<string, unknown>): void {
|
||||||
|
validateBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.URITokenID == null) {
|
||||||
|
throw new ValidationError('URITokenClear: missing field URITokenID')
|
||||||
|
}
|
||||||
|
}
|
||||||
92
packages/xrpl/src/models/transactions/uriTokenMint.ts
Normal file
92
packages/xrpl/src/models/transactions/uriTokenMint.ts
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import { ValidationError } from '../../errors'
|
||||||
|
import { isHex } from '../utils'
|
||||||
|
|
||||||
|
import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transaction Flags for an URITokenMint Transaction.
|
||||||
|
*
|
||||||
|
* @category Transaction Flags
|
||||||
|
*/
|
||||||
|
export enum URITokenMintFlags {
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of flags to boolean values representing {@link URITokenMint} transaction
|
||||||
|
* flags.
|
||||||
|
*
|
||||||
|
* @category Transaction Flags
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const tx: URITokenMint = {
|
||||||
|
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* URI: '697066733A2F2F434944',
|
||||||
|
* TransactionType: 'URITokenMint',
|
||||||
|
* Flags: {
|
||||||
|
* tfBurnable: true,
|
||||||
|
* },
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // Autofill the tx to see how flags actually look compared to the interface usage.
|
||||||
|
* const autofilledTx = await client.autofill(tx)
|
||||||
|
* console.log(autofilledTx)
|
||||||
|
* // {
|
||||||
|
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* // URI: '697066733A2F2F434944',
|
||||||
|
* // TransactionType: 'URITokenMint',
|
||||||
|
* // Flags: 0,
|
||||||
|
* // Sequence: 21970384,
|
||||||
|
* // Fee: '12',
|
||||||
|
* // LastLedgerSequence: 21970404
|
||||||
|
* // }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface URITokenMintFlagsInterface extends GlobalFlags {
|
||||||
|
tfBurnable?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An URITokenMint transaction is effectively a limit order . It defines an
|
||||||
|
* intent to exchange currencies, and creates an Offer object if not completely.
|
||||||
|
* Fulfilled when placed. Offers can be partially fulfilled.
|
||||||
|
*
|
||||||
|
* @category Transaction Models
|
||||||
|
*/
|
||||||
|
export interface URITokenMint extends BaseTransaction {
|
||||||
|
TransactionType: 'URITokenMint'
|
||||||
|
Flags?: number | URITokenMintFlagsInterface
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* This field must be hex-encoded. You can use `convertStringToHex` to
|
||||||
|
* convert this field to the proper encoding.
|
||||||
|
*/
|
||||||
|
URI: string
|
||||||
|
|
||||||
|
Digest?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an URITokenMint at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An URITokenMint Transaction.
|
||||||
|
* @throws When the URITokenMint is Malformed.
|
||||||
|
*/
|
||||||
|
export function validateURITokenMint(tx: Record<string, unknown>): void {
|
||||||
|
validateBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (typeof tx.URI === 'string' && !isHex(tx.URI)) {
|
||||||
|
throw new ValidationError('URITokenMint: URI must be in hex format')
|
||||||
|
}
|
||||||
|
}
|
||||||
89
packages/xrpl/src/models/transactions/uriTokenSell.ts
Normal file
89
packages/xrpl/src/models/transactions/uriTokenSell.ts
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import { ValidationError } from '../../errors'
|
||||||
|
import { Amount } from '../common'
|
||||||
|
|
||||||
|
import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of flags to boolean values representing {@link URITokenSell} transaction
|
||||||
|
* flags.
|
||||||
|
*
|
||||||
|
* @category Transaction Flags
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const tx: URITokenSell = {
|
||||||
|
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
|
||||||
|
* Amount: '1000000',
|
||||||
|
* TransactionType: 'URITokenCreateSellOffer',
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // Autofill the tx to see how flags actually look compared to the interface usage.
|
||||||
|
* const autofilledTx = await client.autofill(tx)
|
||||||
|
* console.log(autofilledTx)
|
||||||
|
* // {
|
||||||
|
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
|
||||||
|
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
|
||||||
|
* // Amount: '1000000',
|
||||||
|
* // TransactionType: 'URITokenCreateSellOffer',
|
||||||
|
* // Sequence: 21970384,
|
||||||
|
* // Fee: '12',
|
||||||
|
* // LastLedgerSequence: 21970404
|
||||||
|
* // }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An URITokenSell transaction is effectively a limit order . It defines an
|
||||||
|
* intent to exchange currencies, and creates an Offer object if not completely.
|
||||||
|
* Fulfilled when placed. Offers can be partially fulfilled.
|
||||||
|
*
|
||||||
|
* @category Transaction Models
|
||||||
|
*/
|
||||||
|
export interface URITokenSell extends BaseTransaction {
|
||||||
|
TransactionType: 'URITokenCreateSellOffer'
|
||||||
|
/**
|
||||||
|
* Identifies the URITokenID of the NFToken object that the
|
||||||
|
* offer references.
|
||||||
|
*/
|
||||||
|
URITokenID: string
|
||||||
|
/**
|
||||||
|
* Indicates the amount expected or offered for the Token.
|
||||||
|
*
|
||||||
|
* The amount must be non-zero, except when this is a sell
|
||||||
|
* offer and the asset is XRP. This would indicate that the current
|
||||||
|
* owner of the token is giving it away free, either to anyone at all,
|
||||||
|
* or to the account identified by the Destination field.
|
||||||
|
*/
|
||||||
|
Amount: Amount
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an URITokenSell at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An URITokenSell Transaction.
|
||||||
|
* @throws When the URITokenSell is Malformed.
|
||||||
|
*/
|
||||||
|
export function validateURITokenSell(tx: Record<string, unknown>): void {
|
||||||
|
validateBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.Account === tx.Destination) {
|
||||||
|
throw new ValidationError(
|
||||||
|
'URITokenSell: Destination and Account must not be equal',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx.URITokenID == null) {
|
||||||
|
throw new ValidationError('URITokenSell: missing field URITokenID')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAmount(tx.Amount)) {
|
||||||
|
throw new ValidationError('URITokenSell: invalid Amount')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
import { convertStringToHex, URITokenMint, URITokenBurn } from '../../../src'
|
||||||
|
import serverUrl from '../serverUrl'
|
||||||
|
import {
|
||||||
|
setupClient,
|
||||||
|
teardownClient,
|
||||||
|
type XrplIntegrationTestContext,
|
||||||
|
} from '../setup'
|
||||||
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
|
// how long before each test case times out
|
||||||
|
const TIMEOUT = 20000
|
||||||
|
|
||||||
|
describe('URITokenMint', function () {
|
||||||
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
testContext = await setupClient(serverUrl)
|
||||||
|
})
|
||||||
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
|
it(
|
||||||
|
'base',
|
||||||
|
async () => {
|
||||||
|
const tx: URITokenMint = {
|
||||||
|
TransactionType: 'URITokenMint',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URI: convertStringToHex('ipfs://CID'),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, tx, testContext.wallet)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
const mintResponse = await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
assert.equal(mintResponse.result.account_objects.length, 1)
|
||||||
|
|
||||||
|
const uriTokenID = mintResponse.result.account_objects[0].index
|
||||||
|
assert.isString(uriTokenID)
|
||||||
|
|
||||||
|
const burnTx: URITokenBurn = {
|
||||||
|
TransactionType: 'URITokenBurn',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URITokenID: uriTokenID,
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, burnTx, testContext.wallet)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
assert.equal(
|
||||||
|
(
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
).result.account_objects.length,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
import { URITokenBuy } from '../../../dist/npm'
|
||||||
|
import {
|
||||||
|
convertStringToHex,
|
||||||
|
URITokenMint,
|
||||||
|
URITokenSell,
|
||||||
|
xrpToDrops,
|
||||||
|
} from '../../../src'
|
||||||
|
import serverUrl from '../serverUrl'
|
||||||
|
import {
|
||||||
|
setupClient,
|
||||||
|
teardownClient,
|
||||||
|
type XrplIntegrationTestContext,
|
||||||
|
} from '../setup'
|
||||||
|
import { generateFundedWallet, testTransaction } from '../utils'
|
||||||
|
|
||||||
|
// how long before each test case times out
|
||||||
|
const TIMEOUT = 20000
|
||||||
|
|
||||||
|
describe('URITokenSell', function () {
|
||||||
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
testContext = await setupClient(serverUrl)
|
||||||
|
})
|
||||||
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
|
it(
|
||||||
|
'base',
|
||||||
|
async () => {
|
||||||
|
const wallet1 = await generateFundedWallet(testContext.client)
|
||||||
|
|
||||||
|
const tx: URITokenMint = {
|
||||||
|
TransactionType: 'URITokenMint',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URI: convertStringToHex('ipfs://CID'),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, tx, testContext.wallet)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
const mintResponse = await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
assert.equal(mintResponse.result.account_objects.length, 1)
|
||||||
|
|
||||||
|
const uriTokenID = mintResponse.result.account_objects[0].index
|
||||||
|
assert.isString(uriTokenID)
|
||||||
|
|
||||||
|
const sellTx: URITokenSell = {
|
||||||
|
TransactionType: 'URITokenCreateSellOffer',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URITokenID: uriTokenID,
|
||||||
|
Amount: xrpToDrops(10),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, sellTx, testContext.wallet)
|
||||||
|
|
||||||
|
// verify amount is on le
|
||||||
|
|
||||||
|
const buyTx: URITokenBuy = {
|
||||||
|
TransactionType: 'URITokenBuy',
|
||||||
|
Account: wallet1.classicAddress,
|
||||||
|
URITokenID: uriTokenID,
|
||||||
|
Amount: xrpToDrops(10),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, buyTx, wallet1)
|
||||||
|
|
||||||
|
// check that wallet1 owns uritoken
|
||||||
|
assert.equal(
|
||||||
|
(
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: wallet1.classicAddress,
|
||||||
|
})
|
||||||
|
).result.account_objects.length,
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
// check that wallet1 does not own uritoken
|
||||||
|
assert.equal(
|
||||||
|
(
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
).result.account_objects.length,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
import { URITokenClear } from '../../../dist/npm'
|
||||||
|
import {
|
||||||
|
convertStringToHex,
|
||||||
|
URITokenMint,
|
||||||
|
URITokenSell,
|
||||||
|
xrpToDrops,
|
||||||
|
} from '../../../src'
|
||||||
|
import serverUrl from '../serverUrl'
|
||||||
|
import {
|
||||||
|
setupClient,
|
||||||
|
teardownClient,
|
||||||
|
type XrplIntegrationTestContext,
|
||||||
|
} from '../setup'
|
||||||
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
|
// how long before each test case times out
|
||||||
|
const TIMEOUT = 20000
|
||||||
|
|
||||||
|
describe('URITokenSell', function () {
|
||||||
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
testContext = await setupClient(serverUrl)
|
||||||
|
})
|
||||||
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
|
it(
|
||||||
|
'base',
|
||||||
|
async () => {
|
||||||
|
const tx: URITokenMint = {
|
||||||
|
TransactionType: 'URITokenMint',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URI: convertStringToHex('ipfs://CID'),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, tx, testContext.wallet)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
const mintResponse = await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
assert.equal(mintResponse.result.account_objects.length, 1)
|
||||||
|
|
||||||
|
const uriTokenID = mintResponse.result.account_objects[0].index
|
||||||
|
assert.isString(uriTokenID)
|
||||||
|
|
||||||
|
const sellTx: URITokenSell = {
|
||||||
|
TransactionType: 'URITokenCreateSellOffer',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URITokenID: uriTokenID,
|
||||||
|
Amount: xrpToDrops(10),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, sellTx, testContext.wallet)
|
||||||
|
|
||||||
|
// verify amount is on le
|
||||||
|
|
||||||
|
const clearTx: URITokenClear = {
|
||||||
|
TransactionType: 'URITokenCancelSellOffer',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URITokenID: uriTokenID,
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, clearTx, testContext.wallet)
|
||||||
|
// verify amount is not on le
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
import { convertStringToHex, URITokenMint } from '../../../src'
|
||||||
|
import serverUrl from '../serverUrl'
|
||||||
|
import {
|
||||||
|
setupClient,
|
||||||
|
teardownClient,
|
||||||
|
type XrplIntegrationTestContext,
|
||||||
|
} from '../setup'
|
||||||
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
|
// how long before each test case times out
|
||||||
|
const TIMEOUT = 20000
|
||||||
|
|
||||||
|
describe('URITokenMint', function () {
|
||||||
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
testContext = await setupClient(serverUrl)
|
||||||
|
})
|
||||||
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
|
it(
|
||||||
|
'base',
|
||||||
|
async () => {
|
||||||
|
const tx: URITokenMint = {
|
||||||
|
TransactionType: 'URITokenMint',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URI: convertStringToHex('ipfs://CID'),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, tx, testContext.wallet)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
assert.equal(
|
||||||
|
(
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
).result.account_objects.length,
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
import {
|
||||||
|
convertStringToHex,
|
||||||
|
URITokenMint,
|
||||||
|
URITokenSell,
|
||||||
|
xrpToDrops,
|
||||||
|
} from '../../../src'
|
||||||
|
import serverUrl from '../serverUrl'
|
||||||
|
import {
|
||||||
|
setupClient,
|
||||||
|
teardownClient,
|
||||||
|
type XrplIntegrationTestContext,
|
||||||
|
} from '../setup'
|
||||||
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
|
// how long before each test case times out
|
||||||
|
const TIMEOUT = 20000
|
||||||
|
|
||||||
|
describe('URITokenSell', function () {
|
||||||
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
testContext = await setupClient(serverUrl)
|
||||||
|
})
|
||||||
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
|
it(
|
||||||
|
'base',
|
||||||
|
async () => {
|
||||||
|
const tx: URITokenMint = {
|
||||||
|
TransactionType: 'URITokenMint',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URI: convertStringToHex('ipfs://CID'),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, tx, testContext.wallet)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
const mintResponse = await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
assert.equal(mintResponse.result.account_objects.length, 1)
|
||||||
|
|
||||||
|
const uriTokenID = mintResponse.result.account_objects[0].index
|
||||||
|
assert.isString(uriTokenID)
|
||||||
|
|
||||||
|
const sellTx: URITokenSell = {
|
||||||
|
TransactionType: 'URITokenCreateSellOffer',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
URITokenID: uriTokenID,
|
||||||
|
Amount: xrpToDrops(10),
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, sellTx, testContext.wallet)
|
||||||
|
|
||||||
|
// verify amount is on le
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user