Skip to content

Commit de4ddd8

Browse files
authored
Replace seed with wallet (#80)
Use wallet instead of seed in the set and clear hook functions.
1 parent 8e49897 commit de4ddd8

34 files changed

+223
-111
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const hook = createHookPayload({
5757

5858
await setHooksV3({
5959
client: testContext.client,
60-
seed: testContext.hook1.seed,
60+
wallet: testContext.hook1,
6161
hooks: [{ Hook: hook }],
6262
} as SetHookParams)
6363
```
@@ -112,7 +112,7 @@ const clearHook = createHookPayload({
112112
})
113113
await setHooksV3({
114114
client: testContext.client,
115-
seed: testContext.hook1.seed,
115+
wallet: testContext.hook1,
116116
hooks: [{Hook: {}}, { Hook: clearHook }],
117117
} as SetHookParams)
118118
```
@@ -524,7 +524,7 @@ const hook = createHookPayload({
524524

525525
await setHooksV3({
526526
client: testContext.client,
527-
seed: testContext.alice.seed,
527+
wallet: testContext.alice,
528528
hooks: [{ Hook: hook }],
529529
} as SetHookParams)
530530

contracts-c/toolbox/operator.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
#include <stdint.h>
3+
#include "hookapi.h"
4+
5+
#define OP3(a, b, c) (((a) << 16) | ((b) << 8) | (c))
6+
7+
int64_t hook(uint32_t r)
8+
{
9+
_g(1, 1);
10+
11+
int64_t tt = otxn_type();
12+
uint8_t op_bytes[4];
13+
if (otxn_param(&op_bytes, 3, "OP", 2) != 3)
14+
NOPE("operator.c: Missing OP parameter.");
15+
16+
uint32_t op = (op_bytes[0] << 16) | (op_bytes[1] << 8) | op_bytes[2];
17+
18+
// action
19+
switch (op)
20+
{
21+
case OP3('O', 'C', 'B'):
22+
{
23+
TRACESTR("operator.c: OCB.");
24+
DONE("operator.c: OCB.");
25+
}
26+
case OP3('O', 'C', 'S'):
27+
{
28+
TRACESTR("operator.c: OCS.");
29+
DONE("operator.c: OCS.");
30+
}
31+
default:
32+
{
33+
NOPE("operator.c: Unknown operation.");
34+
}
35+
}
36+
37+
return 0;
38+
}

src/libs/xrpl-helpers/fundSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export async function setGovernTable(
181181
}
182182
await setHooksV3({
183183
client: client,
184-
seed: table.seed,
184+
wallet: table,
185185
hooks: [{ Hook: hook }],
186186
} as SetHookParams)
187187
const tx: Invoke = {

src/libs/xrpl-helpers/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function teardownHook(
8585
const promises = accounts.map(async (acct: Wallet) => {
8686
await clearAllHooksV3({
8787
client: context.client,
88-
seed: acct.seed,
88+
wallet: acct,
8989
} as SetHookParams)
9090
})
9191
await Promise.all(promises)

src/setHooks.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import {
2-
Wallet,
32
calculateHookOn,
43
hexHookParameters,
54
SetHook,
65
SetHookFlags,
7-
ECDSA,
86
} from 'xahau'
97
import { SetHookParams, iHook } from './types'
108
import { HookGrant, HookParameter } from 'xahau/dist/npm/models/common/xahau'
@@ -68,19 +66,19 @@ export function createHookPayload(payload: SetHookPayload): iHook {
6866
return hook
6967
}
7068

71-
export async function setHooksV3({ client, seed, hooks }: SetHookParams) {
72-
const HOOK_ACCOUNT = Wallet.fromSeed(seed, { algorithm: ECDSA.secp256k1 })
69+
70+
export async function setHooksV3({ client, wallet, hooks }: SetHookParams) {
7371
const tx: SetHook = {
7472
TransactionType: `SetHook`,
75-
Account: HOOK_ACCOUNT.address,
73+
Account: wallet.address,
7674
Hooks: hooks,
7775
}
7876

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

83-
await appTransaction(client, tx, HOOK_ACCOUNT, {
81+
await appTransaction(client, tx, wallet, {
8482
hardFail: true,
8583
count: 2,
8684
delayMs: 1000,
@@ -89,15 +87,15 @@ export async function setHooksV3({ client, seed, hooks }: SetHookParams) {
8987
appLogger.debug(`\n3. SetHook Success...`)
9088
}
9189

92-
export async function clearAllHooksV3({ client, seed }: SetHookParams) {
93-
const HOOK_ACCOUNT = Wallet.fromSeed(seed, { algorithm: ECDSA.secp256k1 })
90+
91+
export async function clearAllHooksV3({ client, wallet }: SetHookParams) {
9492
const hook = {
9593
CreateCode: '',
9694
Flags: SetHookFlags.hsfOverride | SetHookFlags.hsfNSDelete,
9795
} as iHook
9896
const tx: SetHook = {
9997
TransactionType: `SetHook`,
100-
Account: HOOK_ACCOUNT.classicAddress,
98+
Account: wallet.classicAddress,
10199
Hooks: [
102100
{ Hook: hook },
103101
{ Hook: hook },
@@ -116,7 +114,7 @@ export async function clearAllHooksV3({ client, seed }: SetHookParams) {
116114
appLogger.debug(JSON.stringify(tx, null, 2))
117115
appLogger.debug(`\n2. Submitting transaction...`)
118116

119-
await appTransaction(client, tx, HOOK_ACCOUNT, {
117+
await appTransaction(client, tx, wallet, {
120118
hardFail: true,
121119
count: 2,
122120
delayMs: 1000,
@@ -125,19 +123,22 @@ export async function clearAllHooksV3({ client, seed }: SetHookParams) {
125123
appLogger.debug(`\n3. SetHook Success...`)
126124
}
127125

128-
export async function clearHookStateV3({ client, seed, hooks }: SetHookParams) {
129-
const HOOK_ACCOUNT = Wallet.fromSeed(seed, { algorithm: ECDSA.secp256k1 })
126+
export async function clearHookStateV3({
127+
client,
128+
wallet,
129+
hooks,
130+
}: SetHookParams) {
130131
const tx: SetHook = {
131132
TransactionType: `SetHook`,
132-
Account: HOOK_ACCOUNT.classicAddress,
133+
Account: wallet.classicAddress,
133134
Hooks: hooks,
134135
}
135136

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

140-
await appTransaction(client, tx, HOOK_ACCOUNT, {
141+
await appTransaction(client, tx, wallet, {
141142
hardFail: true,
142143
count: 2,
143144
delayMs: 1000,

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type iHook = {
1919

2020
export type SetHookParams = {
2121
client: Client
22-
seed: string
22+
wallet: Wallet
2323
hooks: Hook[]
2424
flags: number | SetHookFlagsInterface
2525
}

test/integration-c/hooks/toolbox/base.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ describe('base', () => {
2929
})
3030
await setHooksV3({
3131
client: testContext.client,
32-
seed: testContext.hook1.seed,
32+
wallet: testContext.hook1,
3333
hooks: [{ Hook: hook }],
3434
} as SetHookParams)
3535
})
3636
afterAll(async () => {
3737
await clearAllHooksV3({
3838
client: testContext.client,
39-
seed: testContext.hook1.seed,
39+
wallet: testContext.hook1,
4040
} as SetHookParams)
4141
await teardownClient(testContext)
4242
})

test/integration-c/hooks/toolbox/callback.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('callback', () => {
4747
})
4848
await setHooksV3({
4949
client: testContext.client,
50-
seed: testContext.hook1.seed,
50+
wallet: testContext.hook1,
5151
hooks: [{ Hook: hook }],
5252
} as SetHookParams)
5353

@@ -76,12 +76,12 @@ describe('callback', () => {
7676

7777
await clearAllHooksV3({
7878
client: testContext.client,
79-
seed: testContext.gw.seed,
79+
wallet: testContext.gw,
8080
} as SetHookParams)
8181

8282
await clearAllHooksV3({
8383
client: testContext.client,
84-
seed: testContext.alice.seed,
84+
wallet: testContext.alice,
8585
} as SetHookParams)
8686
})
8787
it('callback failure', async () => {
@@ -94,7 +94,7 @@ describe('callback', () => {
9494
})
9595
await setHooksV3({
9696
client: testContext.client,
97-
seed: testContext.hook1.seed,
97+
wallet: testContext.hook1,
9898
hooks: [{ Hook: hook }],
9999
} as SetHookParams)
100100

@@ -141,12 +141,12 @@ describe('callback', () => {
141141

142142
await clearAllHooksV3({
143143
client: testContext.client,
144-
seed: testContext.gw.seed,
144+
wallet: testContext.gw,
145145
} as SetHookParams)
146146

147147
await clearAllHooksV3({
148148
client: testContext.client,
149-
seed: testContext.alice.seed,
149+
wallet: testContext.alice,
150150
} as SetHookParams)
151151

152152
await accountClear(

test/integration-c/hooks/toolbox/commonMemo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ describe('commonMemo', () => {
2929
})
3030
await setHooksV3({
3131
client: testContext.client,
32-
seed: testContext.hook1.seed,
32+
wallet: testContext.hook1,
3333
hooks: [{ Hook: hook }],
3434
} as SetHookParams)
3535
})
3636
afterAll(async () => {
3737
await clearAllHooksV3({
3838
client: testContext.client,
39-
seed: testContext.hook1.seed,
39+
wallet: testContext.hook1,
4040
} as SetHookParams)
4141
await teardownClient(testContext)
4242
})

test/integration-c/hooks/toolbox/compareCondition.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ describe('compareCondition', () => {
3434
})
3535
await setHooksV3({
3636
client: testContext.client,
37-
seed: testContext.hook1.seed,
37+
wallet: testContext.hook1,
3838
hooks: [{ Hook: hook }],
3939
} as SetHookParams)
4040
})
4141
afterAll(async () => {
4242
await clearAllHooksV3({
4343
client: testContext.client,
44-
seed: testContext.hook1.seed,
44+
wallet: testContext.hook1,
4545
} as SetHookParams)
4646
await teardownClient(testContext)
4747
})

0 commit comments

Comments
 (0)