Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const hook = createHookPayload({

await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
```
Expand Down Expand Up @@ -112,7 +112,7 @@ const clearHook = createHookPayload({
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{Hook: {}}, { Hook: clearHook }],
} as SetHookParams)
```
Expand Down Expand Up @@ -524,7 +524,7 @@ const hook = createHookPayload({

await setHooksV3({
client: testContext.client,
seed: testContext.alice.seed,
wallet: testContext.alice,
hooks: [{ Hook: hook }],
} as SetHookParams)

Expand Down
38 changes: 38 additions & 0 deletions contracts-c/toolbox/operator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#include <stdint.h>
#include "hookapi.h"

#define OP3(a, b, c) (((a) << 16) | ((b) << 8) | (c))

int64_t hook(uint32_t r)
{
_g(1, 1);

int64_t tt = otxn_type();
uint8_t op_bytes[4];
if (otxn_param(&op_bytes, 3, "OP", 2) != 3)
NOPE("operator.c: Missing OP parameter.");

uint32_t op = (op_bytes[0] << 16) | (op_bytes[1] << 8) | op_bytes[2];

// action
switch (op)
{
case OP3('O', 'C', 'B'):
{
TRACESTR("operator.c: OCB.");
DONE("operator.c: OCB.");
}
case OP3('O', 'C', 'S'):
{
TRACESTR("operator.c: OCS.");
DONE("operator.c: OCS.");
}
default:
{
NOPE("operator.c: Unknown operation.");
}
}

return 0;
}
2 changes: 1 addition & 1 deletion src/libs/xrpl-helpers/fundSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
'0000000000000000000000000000000000000000000000000000000000000000'
)
return true
} catch (error: any) {

Check warning on line 124 in src/libs/xrpl-helpers/fundSystem.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (18.x)

Unexpected any. Specify a different type

Check warning on line 124 in src/libs/xrpl-helpers/fundSystem.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
appLogger.error(error)
return false
}
Expand Down Expand Up @@ -181,7 +181,7 @@
}
await setHooksV3({
client: client,
seed: table.seed,
wallet: table,
hooks: [{ Hook: hook }],
} as SetHookParams)
const tx: Invoke = {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/xrpl-helpers/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function teardownHook(
const promises = accounts.map(async (acct: Wallet) => {
await clearAllHooksV3({
client: context.client,
seed: acct.seed,
wallet: acct,
} as SetHookParams)
})
await Promise.all(promises)
Expand Down
29 changes: 15 additions & 14 deletions src/setHooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
Wallet,
calculateHookOn,
hexHookParameters,
SetHook,
SetHookFlags,
ECDSA,
} from 'xahau'
import { SetHookParams, iHook } from './types'
import { HookGrant, HookParameter } from 'xahau/dist/npm/models/common/xahau'
Expand Down Expand Up @@ -68,19 +66,19 @@ export function createHookPayload(payload: SetHookPayload): iHook {
return hook
}

export async function setHooksV3({ client, seed, hooks }: SetHookParams) {
const HOOK_ACCOUNT = Wallet.fromSeed(seed, { algorithm: ECDSA.secp256k1 })

export async function setHooksV3({ client, wallet, hooks }: SetHookParams) {
const tx: SetHook = {
TransactionType: `SetHook`,
Account: HOOK_ACCOUNT.address,
Account: wallet.address,
Hooks: hooks,
}

appLogger.debug(`1. Transaction to submit (before autofill):`)
appLogger.debug(JSON.stringify(tx, null, 2))
appLogger.debug(`\n2. Submitting transaction...`)

await appTransaction(client, tx, HOOK_ACCOUNT, {
await appTransaction(client, tx, wallet, {
hardFail: true,
count: 2,
delayMs: 1000,
Expand All @@ -89,15 +87,15 @@ export async function setHooksV3({ client, seed, hooks }: SetHookParams) {
appLogger.debug(`\n3. SetHook Success...`)
}

export async function clearAllHooksV3({ client, seed }: SetHookParams) {
const HOOK_ACCOUNT = Wallet.fromSeed(seed, { algorithm: ECDSA.secp256k1 })

export async function clearAllHooksV3({ client, wallet }: SetHookParams) {
const hook = {
CreateCode: '',
Flags: SetHookFlags.hsfOverride | SetHookFlags.hsfNSDelete,
} as iHook
const tx: SetHook = {
TransactionType: `SetHook`,
Account: HOOK_ACCOUNT.classicAddress,
Account: wallet.classicAddress,
Hooks: [
{ Hook: hook },
{ Hook: hook },
Expand All @@ -116,7 +114,7 @@ export async function clearAllHooksV3({ client, seed }: SetHookParams) {
appLogger.debug(JSON.stringify(tx, null, 2))
appLogger.debug(`\n2. Submitting transaction...`)

await appTransaction(client, tx, HOOK_ACCOUNT, {
await appTransaction(client, tx, wallet, {
hardFail: true,
count: 2,
delayMs: 1000,
Expand All @@ -125,19 +123,22 @@ export async function clearAllHooksV3({ client, seed }: SetHookParams) {
appLogger.debug(`\n3. SetHook Success...`)
}

export async function clearHookStateV3({ client, seed, hooks }: SetHookParams) {
const HOOK_ACCOUNT = Wallet.fromSeed(seed, { algorithm: ECDSA.secp256k1 })
export async function clearHookStateV3({
client,
wallet,
hooks,
}: SetHookParams) {
const tx: SetHook = {
TransactionType: `SetHook`,
Account: HOOK_ACCOUNT.classicAddress,
Account: wallet.classicAddress,
Hooks: hooks,
}

appLogger.debug(`1. Transaction to submit (before autofill):`)
appLogger.debug(JSON.stringify(tx, null, 2))
appLogger.debug(`\n2. Submitting transaction...`)

await appTransaction(client, tx, HOOK_ACCOUNT, {
await appTransaction(client, tx, wallet, {
hardFail: true,
count: 2,
delayMs: 1000,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type iHook = {

export type SetHookParams = {
client: Client
seed: string
wallet: Wallet
hooks: Hook[]
flags: number | SetHookFlagsInterface
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration-c/hooks/toolbox/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ describe('base', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
})
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
} as SetHookParams)
await teardownClient(testContext)
})
Expand Down
12 changes: 6 additions & 6 deletions test/integration-c/hooks/toolbox/callback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('callback', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)

Expand Down Expand Up @@ -76,12 +76,12 @@ describe('callback', () => {

await clearAllHooksV3({
client: testContext.client,
seed: testContext.gw.seed,
wallet: testContext.gw,
} as SetHookParams)

await clearAllHooksV3({
client: testContext.client,
seed: testContext.alice.seed,
wallet: testContext.alice,
} as SetHookParams)
})
it('callback failure', async () => {
Expand All @@ -94,7 +94,7 @@ describe('callback', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)

Expand Down Expand Up @@ -141,12 +141,12 @@ describe('callback', () => {

await clearAllHooksV3({
client: testContext.client,
seed: testContext.gw.seed,
wallet: testContext.gw,
} as SetHookParams)

await clearAllHooksV3({
client: testContext.client,
seed: testContext.alice.seed,
wallet: testContext.alice,
} as SetHookParams)

await accountClear(
Expand Down
4 changes: 2 additions & 2 deletions test/integration-c/hooks/toolbox/commonMemo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ describe('commonMemo', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
})
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
} as SetHookParams)
await teardownClient(testContext)
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration-c/hooks/toolbox/compareCondition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ describe('compareCondition', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
})
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
} as SetHookParams)
await teardownClient(testContext)
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration-c/hooks/toolbox/filterOnIO.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ describe('filterOnIO', () => {

await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
})
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
} as SetHookParams)
await teardownClient(testContext)
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration-c/hooks/toolbox/filterOnToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ describe('filterOnToken', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
})
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
} as SetHookParams)
await teardownClient(testContext)
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration-c/hooks/toolbox/filterOnXrp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ describe('filterOnXrp', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
})
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
} as SetHookParams)
await teardownClient(testContext)
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration-c/hooks/toolbox/floatSubtract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ describe('floatSubtract', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
})
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
} as SetHookParams)
await teardownClient(testContext)
})
Expand Down
6 changes: 3 additions & 3 deletions test/integration-c/hooks/toolbox/hookOnTT.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('hookOnTT', () => {
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
} as SetHookParams)
await teardownClient(testContext)
})
Expand All @@ -42,7 +42,7 @@ describe('hookOnTT', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)

Expand Down Expand Up @@ -70,7 +70,7 @@ describe('hookOnTT', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.hook1.seed,
wallet: testContext.hook1,
hooks: [{ Hook: hook }],
} as SetHookParams)
try {
Expand Down
4 changes: 2 additions & 2 deletions test/integration-c/hooks/toolbox/numbers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ describe('numbers', () => {
})
await setHooksV3({
client: testContext.client,
seed: testContext.alice.seed,
wallet: testContext.alice,
hooks: [{ Hook: hook }],
} as SetHookParams)
})
afterAll(async () => {
await clearAllHooksV3({
client: testContext.client,
seed: testContext.alice.seed,
wallet: testContext.alice,
} as SetHookParams)
await teardownClient(testContext)
})
Expand Down
Loading
Loading