Skip to content
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

web3: restructure files into more directories #27080

Merged
merged 4 commits into from
Aug 12, 2022
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
2 changes: 1 addition & 1 deletion web3.js/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import nacl from 'tweetnacl';
import type {SignKeyPair as KeyPair} from 'tweetnacl';
import type {Buffer} from 'buffer';

import {toBuffer} from './util/to-buffer';
import {toBuffer} from './utils/to-buffer';
import {PublicKey} from './publickey';

/**
Expand Down
12 changes: 6 additions & 6 deletions web3.js/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {Struct} from 'superstruct';
import {Client as RpcWebSocketClient} from 'rpc-websockets';
import RpcClient from 'jayson/lib/client/browser';

import {URL} from './util/url-impl';
import {URL} from './utils/url-impl';
import {AgentManager} from './agent-manager';
import {EpochSchedule} from './epoch-schedule';
import {SendTransactionError, SolanaJSONRPCError} from './errors';
Expand All @@ -35,14 +35,14 @@ import {Signer} from './keypair';
import {MS_PER_SLOT} from './timing';
import {Transaction, TransactionStatus} from './transaction';
import {Message} from './message';
import assert from './util/assert';
import {sleep} from './util/sleep';
import {toBuffer} from './util/to-buffer';
import assert from './utils/assert';
import {sleep} from './utils/sleep';
import {toBuffer} from './utils/to-buffer';
import {
TransactionExpiredBlockheightExceededError,
TransactionExpiredTimeoutError,
} from './util/tx-expiry-custom-errors';
import {makeWebsocketUrl} from './util/makeWebsocketUrl';
} from './transaction/expiry-custom-errors';
import {makeWebsocketUrl} from './utils/makeWebsocketUrl';
import type {Blockhash} from './blockhash';
import type {FeeCalculator} from './fee-calculator';
import type {TransactionSignature} from './transaction';
Expand Down
17 changes: 3 additions & 14 deletions web3.js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
export * from './account';
export * from './address-lookup-table-program';
export * from './blockhash';
export * from './bpf-loader-deprecated';
export * from './bpf-loader';
export * from './compute-budget';
export * from './connection';
export * from './epoch-schedule';
export * from './ed25519-program';
export * from './errors';
export * from './fee-calculator';
export * from './keypair';
export * from './loader';
export * from './message';
export * from './nonce-account';
export * from './programs';
export * from './publickey';
export * from './stake-program';
export * from './system-program';
export * from './secp256k1-program';
export * from './transaction';
export * from './transaction-constants';
export * from './validator-info';
export * from './vote-account';
export * from './vote-program';
export * from './sysvar';
export * from './errors';
export * from './util/borsh-schema';
export * from './util/send-and-confirm-transaction';
export * from './util/send-and-confirm-raw-transaction';
export * from './util/tx-expiry-custom-errors';
export * from './util/cluster';
export * from './utils';

/**
* There are 1-billion lamports in one SOL
Expand Down
9 changes: 4 additions & 5 deletions web3.js/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import {Buffer} from 'buffer';
import * as BufferLayout from '@solana/buffer-layout';

import {PublicKey} from './publickey';
import {Transaction} from './transaction';
import {Transaction, PACKET_DATA_SIZE} from './transaction';
import {SYSVAR_RENT_PUBKEY} from './sysvar';
import {sendAndConfirmTransaction} from './util/send-and-confirm-transaction';
import {sleep} from './util/sleep';
import {sendAndConfirmTransaction} from './utils/send-and-confirm-transaction';
import {sleep} from './utils/sleep';
import type {Connection} from './connection';
import type {Signer} from './keypair';
import {SystemProgram} from './system-program';
import {SystemProgram} from './programs/system';
import {IInstructionInputData} from './instruction';
import {PACKET_DATA_SIZE} from './transaction-constants';

// Keep program chunks under PACKET_DATA_SIZE, leaving enough room for the
// rest of the Transaction fields
Expand Down
32 changes: 32 additions & 0 deletions web3.js/src/message/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export * from './legacy';

/**
* The message header, identifying signed and read-only account
*/
export type MessageHeader = {
/**
* The number of signatures required for this message to be considered valid. The
* signatures must match the first `numRequiredSignatures` of `accountKeys`.
*/
numRequiredSignatures: number;
/** The last `numReadonlySignedAccounts` of the signed keys are read-only accounts */
numReadonlySignedAccounts: number;
/** The last `numReadonlySignedAccounts` of the unsigned keys are read-only accounts */
numReadonlyUnsignedAccounts: number;
};

/**
* An instruction to execute by a program
*
* @property {number} programIdIndex
* @property {number[]} accounts
* @property {string} data
*/
export type CompiledInstruction = {
/** Index into the transaction keys array indicating the program account that executes this instruction */
programIdIndex: number;
/** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
accounts: number[];
/** The program input data encoded as base 58 */
data: string;
};
44 changes: 7 additions & 37 deletions web3.js/src/message.ts → web3.js/src/message/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,13 @@ import bs58 from 'bs58';
import {Buffer} from 'buffer';
import * as BufferLayout from '@solana/buffer-layout';

import {PublicKey} from './publickey';
import type {Blockhash} from './blockhash';
import * as Layout from './layout';
import {PACKET_DATA_SIZE} from './transaction-constants';
import * as shortvec from './util/shortvec-encoding';
import {toBuffer} from './util/to-buffer';

/**
* The message header, identifying signed and read-only account
*/
export type MessageHeader = {
/**
* The number of signatures required for this message to be considered valid. The
* signatures must match the first `numRequiredSignatures` of `accountKeys`.
*/
numRequiredSignatures: number;
/** The last `numReadonlySignedAccounts` of the signed keys are read-only accounts */
numReadonlySignedAccounts: number;
/** The last `numReadonlySignedAccounts` of the unsigned keys are read-only accounts */
numReadonlyUnsignedAccounts: number;
};

/**
* An instruction to execute by a program
*
* @property {number} programIdIndex
* @property {number[]} accounts
* @property {string} data
*/
export type CompiledInstruction = {
/** Index into the transaction keys array indicating the program account that executes this instruction */
programIdIndex: number;
/** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
accounts: number[];
/** The program input data encoded as base 58 */
data: string;
};
import {PublicKey} from '../publickey';
import type {Blockhash} from '../blockhash';
import * as Layout from '../layout';
import {PACKET_DATA_SIZE} from '../transaction/constants';
import * as shortvec from '../utils/shortvec-encoding';
import {toBuffer} from '../utils/to-buffer';
import {CompiledInstruction, MessageHeader} from './index';

/**
* Message constructor arguments
Expand Down
2 changes: 1 addition & 1 deletion web3.js/src/nonce-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as Layout from './layout';
import {PublicKey} from './publickey';
import type {FeeCalculator} from './fee-calculator';
import {FeeCalculatorLayout} from './fee-calculator';
import {toBuffer} from './util/to-buffer';
import {toBuffer} from './utils/to-buffer';

/**
* See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {toBufferLE} from 'bigint-buffer';
import * as BufferLayout from '@solana/buffer-layout';

import * as Layout from './layout';
import {PublicKey} from './publickey';
import * as bigintLayout from './util/bigint';
import {SystemProgram} from './system-program';
import {TransactionInstruction} from './transaction';
import {decodeData, encodeData, IInstructionInputData} from './instruction';
import * as Layout from '../layout';
import {PublicKey} from '../publickey';
import * as bigintLayout from '../utils/bigint';
import {SystemProgram} from './system';
import {TransactionInstruction} from '../transaction';
import {decodeData, encodeData, IInstructionInputData} from '../instruction';

export type CreateLookupTableParams = {
/** Account used to derive and control the new address lookup table. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
decodeData,
InstructionType,
IInstructionInputData,
} from './instruction';
import {PublicKey} from './publickey';
import {TransactionInstruction} from './transaction';
import {u64} from './util/bigint';
} from '../instruction';
import {PublicKey} from '../publickey';
import {TransactionInstruction} from '../transaction';
import {u64} from '../utils/bigint';

/**
* Compute Budget Instruction class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {Buffer} from 'buffer';
import * as BufferLayout from '@solana/buffer-layout';
import nacl from 'tweetnacl';

import {Keypair} from './keypair';
import {PublicKey} from './publickey';
import {TransactionInstruction} from './transaction';
import assert from './util/assert';
import {Keypair} from '../keypair';
import {PublicKey} from '../publickey';
import {TransactionInstruction} from '../transaction';
import assert from '../utils/assert';

const PRIVATE_KEY_BYTES = 64;
const PUBLIC_KEY_BYTES = 32;
Expand Down
7 changes: 7 additions & 0 deletions web3.js/src/programs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './address-lookup-table';
export * from './compute-budget';
export * from './ed25519';
export * from './secp256k1';
export * from './stake';
export * from './system';
export * from './vote';
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as BufferLayout from '@solana/buffer-layout';
import secp256k1 from 'secp256k1';
import sha3 from 'js-sha3';

import {PublicKey} from './publickey';
import {TransactionInstruction} from './transaction';
import assert from './util/assert';
import {toBuffer} from './util/to-buffer';
import {PublicKey} from '../publickey';
import {TransactionInstruction} from '../transaction';
import assert from '../utils/assert';
import {toBuffer} from '../utils/to-buffer';

const {publicKeyCreate, ecdsaSign} = secp256k1;

Expand Down
14 changes: 7 additions & 7 deletions web3.js/src/stake-program.ts → web3.js/src/programs/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import {
decodeData,
InstructionType,
IInstructionInputData,
} from './instruction';
import * as Layout from './layout';
import {PublicKey} from './publickey';
import {SystemProgram} from './system-program';
} from '../instruction';
import * as Layout from '../layout';
import {PublicKey} from '../publickey';
import {SystemProgram} from './system';
import {
SYSVAR_CLOCK_PUBKEY,
SYSVAR_RENT_PUBKEY,
SYSVAR_STAKE_HISTORY_PUBKEY,
} from './sysvar';
import {Transaction, TransactionInstruction} from './transaction';
import {toBuffer} from './util/to-buffer';
} from '../sysvar';
import {Transaction, TransactionInstruction} from '../transaction';
import {toBuffer} from '../utils/to-buffer';

/**
* Address of the stake config account which configures the rate
Expand Down
16 changes: 8 additions & 8 deletions web3.js/src/system-program.ts → web3.js/src/programs/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
decodeData,
InstructionType,
IInstructionInputData,
} from './instruction';
import * as Layout from './layout';
import {NONCE_ACCOUNT_LENGTH} from './nonce-account';
import {PublicKey} from './publickey';
import {SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY} from './sysvar';
import {Transaction, TransactionInstruction} from './transaction';
import {toBuffer} from './util/to-buffer';
import {u64} from './util/bigint';
} from '../instruction';
import * as Layout from '../layout';
import {NONCE_ACCOUNT_LENGTH} from '../nonce-account';
import {PublicKey} from '../publickey';
import {SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY} from '../sysvar';
import {Transaction, TransactionInstruction} from '../transaction';
import {toBuffer} from '../utils/to-buffer';
import {u64} from '../utils/bigint';

/**
* Create account system transaction params
Expand Down
14 changes: 7 additions & 7 deletions web3.js/src/vote-program.ts → web3.js/src/programs/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
decodeData,
InstructionType,
IInstructionInputData,
} from './instruction';
import * as Layout from './layout';
import {PublicKey} from './publickey';
import {SystemProgram} from './system-program';
import {SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY} from './sysvar';
import {Transaction, TransactionInstruction} from './transaction';
import {toBuffer} from './util/to-buffer';
} from '../instruction';
import * as Layout from '../layout';
import {PublicKey} from '../publickey';
import {SystemProgram} from './system';
import {SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY} from '../sysvar';
import {Transaction, TransactionInstruction} from '../transaction';
import {toBuffer} from '../utils/to-buffer';

/**
* Vote account info
Expand Down
4 changes: 2 additions & 2 deletions web3.js/src/publickey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {Buffer} from 'buffer';
import nacl from 'tweetnacl';
import {sha256} from '@ethersproject/sha2';

import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
import {toBuffer} from './util/to-buffer';
import {Struct, SOLANA_SCHEMA} from './utils/borsh-schema';
import {toBuffer} from './utils/to-buffer';

/**
* Maximum length of derived pubkey seed
Expand Down
3 changes: 3 additions & 0 deletions web3.js/src/transaction/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './constants';
export * from './expiry-custom-errors';
export * from './legacy';
23 changes: 10 additions & 13 deletions web3.js/src/transaction.ts → web3.js/src/transaction/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import nacl from 'tweetnacl';
import bs58 from 'bs58';
import {Buffer} from 'buffer';

import {
PACKET_DATA_SIZE,
SIGNATURE_LENGTH_IN_BYTES,
} from './transaction-constants';
import {Connection} from './connection';
import {Message} from './message';
import {PublicKey} from './publickey';
import * as shortvec from './util/shortvec-encoding';
import {toBuffer} from './util/to-buffer';
import invariant from './util/assert';
import type {Signer} from './keypair';
import type {Blockhash} from './blockhash';
import type {CompiledInstruction} from './message';
import {PACKET_DATA_SIZE, SIGNATURE_LENGTH_IN_BYTES} from './constants';
import {Connection} from '../connection';
import {Message} from '../message';
import {PublicKey} from '../publickey';
import * as shortvec from '../utils/shortvec-encoding';
import {toBuffer} from '../utils/to-buffer';
import invariant from '../utils/assert';
import type {Signer} from '../keypair';
import type {Blockhash} from '../blockhash';
import type {CompiledInstruction} from '../message';

/**
* Transaction signature as base-58 encoded string
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions web3.js/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './borsh-schema';
export * from './cluster';
export * from './send-and-confirm-raw-transaction';
export * from './send-and-confirm-transaction';
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion web3.js/src/validator-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'superstruct';

import * as Layout from './layout';
import * as shortvec from './util/shortvec-encoding';
import * as shortvec from './utils/shortvec-encoding';
import {PublicKey} from './publickey';

export const VALIDATOR_INFO_KEY = new PublicKey(
Expand Down
2 changes: 1 addition & 1 deletion web3.js/src/vote-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Buffer} from 'buffer';

import * as Layout from './layout';
import {PublicKey} from './publickey';
import {toBuffer} from './util/to-buffer';
import {toBuffer} from './utils/to-buffer';

export const VOTE_PROGRAM_ID = new PublicKey(
'Vote111111111111111111111111111111111111111',
Expand Down
Loading