Skip to content

[DO NOT MERGE] Smart Escrows #2928

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ripple-binary-codec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ripple-binary-codec",
"version": "2.3.0",
"version": "2.4.0-smartescrow.0",
"description": "XRP Ledger binary codec",
"files": [
"dist/*",
Expand Down
31 changes: 31 additions & 0 deletions packages/ripple-binary-codec/src/enums/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,26 @@
"type": "UInt32"
}
],
[
"ExtensionComputeLimit",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": false,
"nth": 52,
"type": "UInt32"
}
],
[
"ExtensionSizeLimit",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": false,
"nth": 53,
"type": "UInt32"
}
],
[
"IndexNext",
{
Expand Down Expand Up @@ -1850,6 +1870,16 @@
"type": "Blob"
}
],
[
"FinishFunction",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": true,
"nth": 32,
"type": "Blob"
}
],
[
"Account",
{
Expand Down Expand Up @@ -2963,6 +2993,7 @@
"tecUNFUNDED_AMM": 162,
"tecUNFUNDED_OFFER": 103,
"tecUNFUNDED_PAYMENT": 104,
"tecWASM_REJECTED": 194,
"tecXCHAIN_ACCOUNT_CREATE_PAST": 181,
"tecXCHAIN_ACCOUNT_CREATE_TOO_MANY": 182,
"tecXCHAIN_BAD_CLAIM_ID": 172,
Expand Down
25 changes: 18 additions & 7 deletions packages/ripple-binary-codec/src/types/st-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,25 @@ class STObject extends SerializedType {
return Object.assign(acc, handled ?? { [key]: val })
}, {})

let sorted = Object.keys(xAddressDecoded)
.map((f: string): FieldInstance => definitions.field[f] as FieldInstance)
.filter(
(f: FieldInstance): boolean =>
f !== undefined &&
xAddressDecoded[f.name] !== undefined &&
f.isSerialized,
function isValidFieldInstance(
f: FieldInstance | undefined,
): f is FieldInstance {
return (
f !== undefined &&
xAddressDecoded[f.name] !== undefined &&
f.isSerialized
)
}

let sorted = Object.keys(xAddressDecoded)
.map((f: string): FieldInstance | undefined => {
if (!(f in definitions.field)) {
if (f[0] === f[0].toLowerCase()) return undefined
throw new Error(`Field ${f} is not defined in the definitions`)
}
return definitions.field[f] as FieldInstance
})
.filter(isValidFieldInstance)
.sort((a, b) => {
return a.ordinal - b.ordinal
})
Expand Down
12 changes: 6 additions & 6 deletions packages/ripple-binary-codec/test/definitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('encode and decode using new types as a parameter', function () {
it('can encode and decode a new Field', function () {
const tx = { ...txJson, NewFieldDefinition: 10 }

// Before updating the types, undefined fields will be ignored on encode
expect(decode(encode(tx))).not.toEqual(tx)
// Before updating the types, undefined fields will throw an error
expect(() => encode(tx)).toThrow()

// Normally this would be generated directly from rippled with something like `server_definitions`.
// Added here to make it easier to see what is actually changing in the definitions.json file.
Expand Down Expand Up @@ -72,8 +72,8 @@ describe('encode and decode using new types as a parameter', function () {
],
}

// Before updating the types, undefined fields will be ignored on encode
expect(decode(encode(tx))).not.toEqual(tx)
// Before updating the types, undefined fields will throw an error
expect(() => encode(tx)).toThrow()

// Normally this would be generated directly from rippled with something like `server_definitions`.
// Added here to make it easier to see what is actually changing in the definitions.json file.
Expand Down Expand Up @@ -141,8 +141,8 @@ describe('encode and decode using new types as a parameter', function () {
},
])

// Test that before updating the types this tx fails to decode correctly. Note that undefined fields are ignored on encode.
expect(decode(encode(tx))).not.toEqual(tx)
// Test that before updating the types this tx fails to decode correctly. Note that undefined fields will throw an error.
expect(() => encode(tx)).toThrow()

class NewType extends UInt32 {
// Should be the same as UInt32
Expand Down
9 changes: 9 additions & 0 deletions packages/ripple-binary-codec/test/tx-encode-decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,13 @@ describe('encoding and decoding tx_json', function () {
encode(my_tx)
}).toThrow()
})

it('throws when there is an unknown field', function () {
const my_tx = Object.assign({}, tx_json, {
BadField: 1,
})
expect(() => {
encode(my_tx)
}).toThrow()
})
})
4 changes: 2 additions & 2 deletions packages/xrpl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xrpl",
"version": "4.2.0",
"version": "4.3.0-smartescrow.1",
"license": "ISC",
"description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser",
"files": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"bignumber.js": "^9.0.0",
"eventemitter3": "^5.0.1",
"ripple-address-codec": "^5.0.0",
"ripple-binary-codec": "^2.3.0",
"ripple-binary-codec": "^2.4.0-alpha.0",
"ripple-keypairs": "^2.0.0"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions packages/xrpl/src/Wallet/defaultFaucets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export interface FaucetWallet {
export enum FaucetNetwork {
Testnet = 'faucet.altnet.rippletest.net',
Devnet = 'faucet.devnet.rippletest.net',
WasmDevnet = 'wasmfaucet.devnet.rippletest.net',
}

export const FaucetNetworkPaths: Record<string, string> = {
[FaucetNetwork.Testnet]: '/accounts',
[FaucetNetwork.Devnet]: '/accounts',
[FaucetNetwork.WasmDevnet]: '/accounts',
}

/**
Expand All @@ -42,6 +44,10 @@ export function getFaucetHost(client: Client): FaucetNetwork | undefined {
)
}

if (connectionUrl.includes('wasm')) {
return FaucetNetwork.WasmDevnet
}

if (connectionUrl.includes('devnet')) {
return FaucetNetwork.Devnet
}
Expand Down
4 changes: 4 additions & 0 deletions packages/xrpl/src/models/ledger/Escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ export default interface Escrow extends BaseLedgerEntry, HasPreviousTxnID {
* this object, in case the directory consists of multiple pages.
*/
DestinationNode?: string

FinishFunction?: string

Data?: string
}
4 changes: 4 additions & 0 deletions packages/xrpl/src/models/ledger/FeeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface FeeSettingsPostAmendmentFields {
ReserveBaseDrops: string
/** The incremental owner reserve for owning objects, as drops of XRP. */
ReserveIncrementDrops: string

ExtensionComputeLimit: number

ExtensionSizeLimit: number
}

export interface FeeSettingsBase
Expand Down
12 changes: 10 additions & 2 deletions packages/xrpl/src/models/transactions/escrowCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export interface EscrowCreate extends BaseTransaction {
* payment, such as a hosted recipient at the destination address.
*/
DestinationTag?: number

FinishFunction?: string

Data?: string
}

/**
Expand Down Expand Up @@ -75,9 +79,13 @@ export function validateEscrowCreate(tx: Record<string, unknown>): void {
)
}

if (tx.FinishAfter === undefined && tx.Condition === undefined) {
if (
tx.FinishAfter === undefined &&
tx.Condition === undefined &&
tx.FinishFunction === undefined
) {
throw new ValidationError(
'EscrowCreate: Either Condition or FinishAfter must be specified',
'EscrowCreate: Either FinishAfter, Condition, or FinishFunction must be specified',
)
}

Expand Down
4 changes: 4 additions & 0 deletions packages/xrpl/src/sugar/autofill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ export async function calculateFeePerTransactionType(
)
baseFee = product.dp(0, BigNumber.ROUND_CEIL)
}
// EscrowCreate transaction with FinishFunction
if (tx.TransactionType === 'EscrowCreate' && tx.FinishFunction != null) {
baseFee = BigNumber.sum(baseFee, 1000)
}

if (
tx.TransactionType === 'AccountDelete' ||
Expand Down
14 changes: 12 additions & 2 deletions packages/xrpl/test/integration/fundWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const TIMEOUT = 60000
// This test is reliant on external networks, and as such may be flaky.
describe('fundWallet', function () {
it(
'submit generates a testnet wallet',
'generates a testnet wallet',
async function () {
await generate_faucet_wallet_and_fund_again(
'wss://s.altnet.rippletest.net:51233',
Expand All @@ -65,7 +65,7 @@ describe('fundWallet', function () {
)

it(
'submit generates a devnet wallet',
'generates a devnet wallet',
async function () {
await generate_faucet_wallet_and_fund_again(
'wss://s.devnet.rippletest.net:51233',
Expand All @@ -74,6 +74,16 @@ describe('fundWallet', function () {
TIMEOUT,
)

it(
'generates a WASM devnet wallet',
async function () {
await generate_faucet_wallet_and_fund_again(
'wss://wasm.devnet.rippletest.net:51233',
)
},
TIMEOUT,
)

// TODO: Investigate why this test is timing out on the browser
// it('can generate and fund wallets using a custom host and path', async function () {
// await generate_faucet_wallet_and_fund_again(
Expand Down
Loading
Loading