@xandeum/web3.js 1.3.5 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/move.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
6
 
7
7
  /**
8
8
  * Constructs a Solana transaction to copy a file or directory from one path to another.
@@ -33,13 +33,18 @@ export async function move (
33
33
 
34
34
  const rest = Buffer.from(`${srcPath}\0${destPath}\0${name}`, 'utf-8')
35
35
 
36
- const instructionData = Buffer.concat([
37
- Buffer.from(Int8Array.from([0]).buffer),
38
- Buffer.from(Int8Array.from([13]).buffer),
39
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
36
+ // inner_data: [13u8 (operation), fsid as u64 LE, paths]
37
+ const innerData = Buffer.concat([
38
+ Buffer.from([13]),
39
+ Buffer.from(new BN(fsid).toArray('le', 8)),
40
40
  rest
41
41
  ])
42
+
43
+ const instructionData = buildInstructionData(innerData)
42
44
  let feeDistributorPda = getFeeDistributorPda()
45
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
46
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
47
+
43
48
  const instruction = new TransactionInstruction({
44
49
  keys: [
45
50
  {
@@ -51,6 +56,21 @@ export async function move (
51
56
  pubkey: feeDistributorPda.pda,
52
57
  isSigner: false,
53
58
  isWritable: true
59
+ },
60
+ {
61
+ pubkey: payerAta.ata,
62
+ isSigner: false,
63
+ isWritable: true
64
+ },
65
+ {
66
+ pubkey: feeAta.ata,
67
+ isSigner: false,
68
+ isWritable: true
69
+ },
70
+ {
71
+ pubkey: TOKEN_PROGRAM_ID,
72
+ isSigner: false,
73
+ isWritable: false
54
74
  }
55
75
  ],
56
76
  programId: new PublicKey(programId),
package/src/peek.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
6
 
7
7
  /**
8
8
  * Constructs a Solana transaction to perform a "peek" operation on a file within a file system.
@@ -28,15 +28,21 @@ export async function peek (
28
28
  sanitizePath(path)
29
29
 
30
30
  const rest = Buffer.from(`${path}`, 'utf-8')
31
- const instructionData = Buffer.concat([
32
- Buffer.from(Int8Array.from([0]).buffer),
33
- Buffer.from(Int8Array.from([3]).buffer),
34
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
35
- Buffer.from(Uint8Array.of(...new BN(startPosition).toArray('le', 8))),
36
- Buffer.from(Uint8Array.of(...new BN(endPosition).toArray('le', 8))),
31
+
32
+ // inner_data: [3u8 (operation), fsid as u64 LE, startPosition as u64 LE, endPosition as u64 LE, path]
33
+ const innerData = Buffer.concat([
34
+ Buffer.from([3]),
35
+ Buffer.from(new BN(fsid).toArray('le', 8)),
36
+ Buffer.from(new BN(startPosition).toArray('le', 8)),
37
+ Buffer.from(new BN(endPosition).toArray('le', 8)),
37
38
  rest
38
39
  ])
40
+
41
+ const instructionData = buildInstructionData(innerData)
39
42
  let feeDistributorPda = getFeeDistributorPda()
43
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
44
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
45
+
40
46
  const instruction = new TransactionInstruction({
41
47
  keys: [
42
48
  {
@@ -48,6 +54,21 @@ export async function peek (
48
54
  pubkey: feeDistributorPda.pda,
49
55
  isSigner: false,
50
56
  isWritable: true
57
+ },
58
+ {
59
+ pubkey: payerAta.ata,
60
+ isSigner: false,
61
+ isWritable: true
62
+ },
63
+ {
64
+ pubkey: feeAta.ata,
65
+ isSigner: false,
66
+ isWritable: true
67
+ },
68
+ {
69
+ pubkey: TOKEN_PROGRAM_ID,
70
+ isSigner: false,
71
+ isWritable: false
51
72
  }
52
73
  ],
53
74
  programId: new PublicKey(programId),
package/src/poke.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
6
 
7
7
  /**
8
- * Constructs a Solana transaction to perform a poke\operation, which writes data
8
+ * Constructs a Solana transaction to perform a poke operation, which writes data
9
9
  * to a file at the specified path and byte position.
10
10
  *
11
11
  * @param fsid - A stringified integer representing the file system ID where the file resides.
@@ -29,16 +29,22 @@ export async function poke (
29
29
  // Encode the path as UTF-8
30
30
  const pathBuffer = Buffer.from(path, 'utf-8')
31
31
  // Encode the path length as an 8-byte little-endian unsigned integer
32
- const pathLengthBuffer = Buffer.from(Uint8Array.of(...new BN(pathBuffer.length).toArray('le', 8)))
33
- const instructionData = Buffer.concat([
34
- Buffer.from(Int8Array.from([0]).buffer),
35
- Buffer.from(Int8Array.from([4]).buffer),
36
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
37
- Buffer.from(Uint8Array.of(...new BN(position).toArray('le', 8))),
32
+ const pathLengthBuffer = Buffer.from(new BN(pathBuffer.length).toArray('le', 8))
33
+
34
+ // inner_data: [4u8 (operation), fsid as u64 LE, position as u64 LE, pathLength as u64 LE, path]
35
+ const innerData = Buffer.concat([
36
+ Buffer.from([4]),
37
+ Buffer.from(new BN(fsid).toArray('le', 8)),
38
+ Buffer.from(new BN(position).toArray('le', 8)),
38
39
  pathLengthBuffer,
39
40
  pathBuffer
40
41
  ])
42
+
43
+ const instructionData = buildInstructionData(innerData)
41
44
  let feeDistributorPda = getFeeDistributorPda()
45
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
46
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
47
+
42
48
  const instruction = new TransactionInstruction({
43
49
  keys: [
44
50
  {
@@ -55,6 +61,21 @@ export async function poke (
55
61
  pubkey: feeDistributorPda.pda,
56
62
  isSigner: false,
57
63
  isWritable: true
64
+ },
65
+ {
66
+ pubkey: payerAta.ata,
67
+ isSigner: false,
68
+ isWritable: true
69
+ },
70
+ {
71
+ pubkey: feeAta.ata,
72
+ isSigner: false,
73
+ isWritable: true
74
+ },
75
+ {
76
+ pubkey: TOKEN_PROGRAM_ID,
77
+ isSigner: false,
78
+ isWritable: false
58
79
  }
59
80
  ],
60
81
  programId: new PublicKey(programId),
@@ -1,8 +1,9 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
+
6
7
  /**
7
8
  * Constructs a Solana transaction to perform a "remove directory" operation
8
9
  * in a file system, identified by a file system ID (`fsid`).
@@ -20,13 +21,18 @@ export async function removeDirectory (
20
21
  wallet: PublicKey
21
22
  ): Promise<Transaction> {
22
23
  sanitizePath(path)
23
- const instructionData = Buffer.concat([
24
- Buffer.from(Int8Array.from([0]).buffer),
25
- Buffer.from(Int8Array.from([7]).buffer),
26
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
24
+ // inner_data: [7u8 (operation), fsid as u64 LE, path]
25
+ const innerData = Buffer.concat([
26
+ Buffer.from([7]),
27
+ Buffer.from(new BN(fsid).toArray('le', 8)),
27
28
  Buffer.from(`${path}`, 'utf-8')
28
29
  ])
30
+
31
+ const instructionData = buildInstructionData(innerData)
29
32
  let feeDistributorPda = getFeeDistributorPda()
33
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
34
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
35
+
30
36
  const instruction = new TransactionInstruction({
31
37
  keys: [
32
38
  {
@@ -38,6 +44,21 @@ export async function removeDirectory (
38
44
  pubkey: feeDistributorPda.pda,
39
45
  isSigner: false,
40
46
  isWritable: true
47
+ },
48
+ {
49
+ pubkey: payerAta.ata,
50
+ isSigner: false,
51
+ isWritable: true
52
+ },
53
+ {
54
+ pubkey: feeAta.ata,
55
+ isSigner: false,
56
+ isWritable: true
57
+ },
58
+ {
59
+ pubkey: TOKEN_PROGRAM_ID,
60
+ isSigner: false,
61
+ isWritable: false
41
62
  }
42
63
  ],
43
64
  programId: new PublicKey(programId),
package/src/removeFile.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
+
6
7
  /**
7
8
  * Constructs a Solana transaction to remove a file from a file system,
8
9
  * identified by a file system ID (`fsid`) and a UTF-8 encoded file path.
@@ -21,13 +22,18 @@ export async function removeFile (
21
22
  ): Promise<Transaction> {
22
23
  sanitizePath(path)
23
24
 
24
- const instructionData = Buffer.concat([
25
- Buffer.from(Int8Array.from([0]).buffer),
26
- Buffer.from(Int8Array.from([5]).buffer),
27
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
25
+ // inner_data: [5u8 (operation), fsid as u64 LE, path]
26
+ const innerData = Buffer.concat([
27
+ Buffer.from([5]),
28
+ Buffer.from(new BN(fsid).toArray('le', 8)),
28
29
  Buffer.from(`${path}`, 'utf-8')
29
30
  ])
31
+
32
+ const instructionData = buildInstructionData(innerData)
30
33
  let feeDistributorPda = getFeeDistributorPda()
34
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
35
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
36
+
31
37
  const instruction = new TransactionInstruction({
32
38
  keys: [
33
39
  {
@@ -39,6 +45,21 @@ export async function removeFile (
39
45
  pubkey: feeDistributorPda.pda,
40
46
  isSigner: false,
41
47
  isWritable: true
48
+ },
49
+ {
50
+ pubkey: payerAta.ata,
51
+ isSigner: false,
52
+ isWritable: true
53
+ },
54
+ {
55
+ pubkey: feeAta.ata,
56
+ isSigner: false,
57
+ isWritable: true
58
+ },
59
+ {
60
+ pubkey: TOKEN_PROGRAM_ID,
61
+ isSigner: false,
62
+ isWritable: false
42
63
  }
43
64
  ],
44
65
  programId: new PublicKey(programId),
package/src/renamePath.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
+
6
7
  /**
7
8
  * Constructs a Solana transaction to rename (or move) a file or directory
8
9
  * within a file system, based on a provided file system ID (`fsid`).
@@ -27,13 +28,18 @@ export async function renamePath (
27
28
 
28
29
  const rest = Buffer.from(`${oldPath}\0${name}`, 'utf-8')
29
30
 
30
- const instructionData = Buffer.concat([
31
- Buffer.from(Int8Array.from([0]).buffer),
32
- Buffer.from(Int8Array.from([8]).buffer),
33
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
31
+ // inner_data: [8u8 (operation), fsid as u64 LE, paths]
32
+ const innerData = Buffer.concat([
33
+ Buffer.from([8]),
34
+ Buffer.from(new BN(fsid).toArray('le', 8)),
34
35
  rest
35
36
  ])
37
+
38
+ const instructionData = buildInstructionData(innerData)
36
39
  let feeDistributorPda = getFeeDistributorPda()
40
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
41
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
42
+
37
43
  const instruction = new TransactionInstruction({
38
44
  keys: [
39
45
  {
@@ -45,6 +51,21 @@ export async function renamePath (
45
51
  pubkey: feeDistributorPda.pda,
46
52
  isSigner: false,
47
53
  isWritable: true
54
+ },
55
+ {
56
+ pubkey: payerAta.ata,
57
+ isSigner: false,
58
+ isWritable: true
59
+ },
60
+ {
61
+ pubkey: feeAta.ata,
62
+ isSigner: false,
63
+ isWritable: true
64
+ },
65
+ {
66
+ pubkey: TOKEN_PROGRAM_ID,
67
+ isSigner: false,
68
+ isWritable: false
48
69
  }
49
70
  ],
50
71
  programId: new PublicKey(programId),