Skip to content

Commit

Permalink
chore: restructure utils code
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Aug 11, 2022
1 parent 027d980 commit 441c4cc
Show file tree
Hide file tree
Showing 43 changed files with 53 additions and 51 deletions.
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
8 changes: 2 additions & 6 deletions web3.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './bpf-loader-deprecated';
export * from './bpf-loader';
export * from './connection';
export * from './epoch-schedule';
export * from './errors';
export * from './fee-calculator';
export * from './keypair';
export * from './loader';
Expand All @@ -15,12 +16,7 @@ export * from './transaction';
export * from './validator-info';
export * from './vote-account';
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
4 changes: 2 additions & 2 deletions web3.js/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as BufferLayout from '@solana/buffer-layout';
import {PublicKey} from './publickey';
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 './programs/system';
Expand Down
4 changes: 2 additions & 2 deletions web3.js/src/message/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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';
import * as shortvec from '../utils/shortvec-encoding';
import {toBuffer} from '../utils/to-buffer';
import {CompiledInstruction, MessageHeader} from './index';

/**
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
2 changes: 1 addition & 1 deletion web3.js/src/programs/address-lookup-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as BufferLayout from '@solana/buffer-layout';

import * as Layout from '../layout';
import {PublicKey} from '../publickey';
import * as bigintLayout from '../util/bigint';
import * as bigintLayout from '../utils/bigint';
import {SystemProgram} from './system';
import {TransactionInstruction} from '../transaction';
import {decodeData, encodeData, IInstructionInputData} from '../instruction';
Expand Down
2 changes: 1 addition & 1 deletion web3.js/src/programs/compute-budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../instruction';
import {PublicKey} from '../publickey';
import {TransactionInstruction} from '../transaction';
import {u64} from '../util/bigint';
import {u64} from '../utils/bigint';

/**
* Compute Budget Instruction class
Expand Down
2 changes: 1 addition & 1 deletion web3.js/src/programs/ed25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import nacl from 'tweetnacl';
import {Keypair} from '../keypair';
import {PublicKey} from '../publickey';
import {TransactionInstruction} from '../transaction';
import assert from '../util/assert';
import assert from '../utils/assert';

const PRIVATE_KEY_BYTES = 64;
const PUBLIC_KEY_BYTES = 32;
Expand Down
4 changes: 2 additions & 2 deletions web3.js/src/programs/secp256k1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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 assert from '../utils/assert';
import {toBuffer} from '../utils/to-buffer';

const {publicKeyCreate, ecdsaSign} = secp256k1;

Expand Down
2 changes: 1 addition & 1 deletion web3.js/src/programs/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
SYSVAR_STAKE_HISTORY_PUBKEY,
} from '../sysvar';
import {Transaction, TransactionInstruction} from '../transaction';
import {toBuffer} from '../util/to-buffer';
import {toBuffer} from '../utils/to-buffer';

/**
* Address of the stake config account which configures the rate
Expand Down
4 changes: 2 additions & 2 deletions web3.js/src/programs/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ 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';
import {toBuffer} from '../utils/to-buffer';
import {u64} from '../utils/bigint';

/**
* Create account system transaction params
Expand Down
2 changes: 1 addition & 1 deletion web3.js/src/programs/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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 '../util/to-buffer';
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
File renamed without changes.
1 change: 1 addition & 0 deletions web3.js/src/transaction/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './constants';
export * from './expiry-custom-errors';
export * from './legacy';
6 changes: 3 additions & 3 deletions web3.js/src/transaction/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ 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 '../util/shortvec-encoding';
import {toBuffer} from '../util/to-buffer';
import invariant from '../util/assert';
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';
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.
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
2 changes: 1 addition & 1 deletion web3.js/test/agent-manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect} from 'chai';

import {AgentManager, DESTROY_TIMEOUT_MS} from '../src/agent-manager';
import {sleep} from '../src/util/sleep';
import {sleep} from '../src/utils/sleep';

describe('AgentManager', () => {
it('works', async () => {
Expand Down
2 changes: 1 addition & 1 deletion web3.js/test/cluster.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect} from 'chai';

import {clusterApiUrl} from '../src/util/cluster';
import {clusterApiUrl} from '../src/utils/cluster';

describe('Cluster Util', () => {
it('invalid', () => {
Expand Down
15 changes: 8 additions & 7 deletions web3.js/test/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Keypair,
Message,
} from '../src';
import invariant from '../src/util/assert';
import invariant from '../src/utils/assert';
import {MOCK_PORT, url} from './url';
import {
AccountInfo,
Expand All @@ -35,7 +35,7 @@ import {
SignatureResult,
SlotInfo,
} from '../src/connection';
import {sleep} from '../src/util/sleep';
import {sleep} from '../src/utils/sleep';
import {
helpers,
mockErrorMessage,
Expand All @@ -49,16 +49,17 @@ import {
restoreRpcWebSocket,
mockRpcMessage,
} from './mocks/rpc-websockets';
import {TransactionInstruction, TransactionSignature} from '../src/transaction';
import {
TransactionInstruction,
TransactionSignature,
TransactionExpiredBlockheightExceededError,
TransactionExpiredTimeoutError,
} from '../src/transaction';
import type {
SignatureStatus,
TransactionError,
KeyedAccountInfo,
} from '../src/connection';
import {
TransactionExpiredBlockheightExceededError,
TransactionExpiredTimeoutError,
} from '../src/util/tx-expiry-custom-errors';

use(chaiAsPromised);

Expand Down
2 changes: 1 addition & 1 deletion web3.js/test/mocks/rpc-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as mockttp from 'mockttp';

import {mockRpcMessage} from './rpc-websockets';
import {Connection, PublicKey, Transaction, Signer} from '../../src';
import invariant from '../../src/util/assert';
import invariant from '../../src/utils/assert';
import type {Commitment, HttpHeaders, RpcParams} from '../../src/connection';

export const mockServer: mockttp.Mockttp | undefined =
Expand Down
2 changes: 1 addition & 1 deletion web3.js/test/program-tests/address-lookup-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Connection,
sendAndConfirmTransaction,
} from '../../src';
import {sleep} from '../../src/util/sleep';
import {sleep} from '../../src/utils/sleep';
import {helpers} from '../mocks/rpc-http';
import {url} from '../url';

Expand Down
2 changes: 1 addition & 1 deletion web3.js/test/program-tests/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
LAMPORTS_PER_SOL,
} from '../../src';
import {NONCE_ACCOUNT_LENGTH} from '../../src/nonce-account';
import {sleep} from '../../src/util/sleep';
import {sleep} from '../../src/utils/sleep';
import {helpers} from '../mocks/rpc-http';
import {url} from '../url';

Expand Down
2 changes: 1 addition & 1 deletion web3.js/test/shortvec-encoding.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect} from 'chai';

import {decodeLength, encodeLength} from '../src/util/shortvec-encoding';
import {decodeLength, encodeLength} from '../src/utils/shortvec-encoding';

function checkDecodedArray(array: Array<number>, expectedValue: number) {
expect(decodeLength(array)).to.eq(expectedValue);
Expand Down
2 changes: 1 addition & 1 deletion web3.js/test/transaction-payer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SystemProgram,
LAMPORTS_PER_SOL,
} from '../src';
import invariant from '../src/util/assert';
import invariant from '../src/utils/assert';
import {MOCK_PORT, url} from './url';
import {helpers, mockRpcResponse, mockServer} from './mocks/rpc-http';
import {stubRpcWebSocket, restoreRpcWebSocket} from './mocks/rpc-websockets';
Expand Down
4 changes: 2 additions & 2 deletions web3.js/test/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {PublicKey} from '../src/publickey';
import {Transaction, TransactionInstruction} from '../src/transaction';
import {StakeProgram, SystemProgram} from '../src/programs';
import {Message} from '../src/message';
import invariant from '../src/util/assert';
import {toBuffer} from '../src/util/to-buffer';
import invariant from '../src/utils/assert';
import {toBuffer} from '../src/utils/to-buffer';
import {helpers} from './mocks/rpc-http';
import {url} from './url';

Expand Down
2 changes: 1 addition & 1 deletion web3.js/test/websocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chaiAsPromised from 'chai-as-promised';

import {Connection} from '../src';
import {url, wsUrl} from './url';
import {sleep} from '../src/util/sleep';
import {sleep} from '../src/utils/sleep';

use(chaiAsPromised);

Expand Down

0 comments on commit 441c4cc

Please sign in to comment.