-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed old pvm builder and apis
BREAKING CHANGE: The old PVM transaction builder has been removed. The new Etna builder is now the default builder in order to support dynamic fees. Static fees on P-chain are not longer applicable. Likewise, API's referring to retrieving static fees have been removed where no longer applicable, and new X-Chain specific API's have been added to cover retrieving static tx fees specific to X-Chain transactions. The `e` alias on `pvm` (ie `pvm.e.{builderMethod}`) has been marked deprecated since the builder methods are now directly available on the `pvm` export.
- Loading branch information
Showing
35 changed files
with
431 additions
and
2,903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,41 @@ | ||
import { addTxSignatures } from '../../src/signer'; | ||
import { TransferableOutput } from '../../src/serializable/avax'; | ||
import { bech32ToBytes, hexToBuffer } from '../../src/utils'; | ||
import { getContextFromURI } from '../../src/vms/context'; | ||
import { newBaseTx } from '../../src/vms/pvm'; | ||
import { pvmapi } from '../chain_apis'; | ||
import { TransferableOutput, addTxSignatures, pvm, utils } from '../../src'; | ||
import { getEnvVars } from '../utils/getEnvVars'; | ||
import { setupEtnaExample } from './utils/etna-helper'; | ||
|
||
/** | ||
* The amount of AVAX to send to self. | ||
*/ | ||
const SEND_AVAX_AMOUNT: number = 0.001; | ||
|
||
const main = async () => { | ||
const { AVAX_PUBLIC_URL, P_CHAIN_ADDRESS, PRIVATE_KEY } = getEnvVars(); | ||
|
||
const { utxos } = await pvmapi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] }); | ||
const context = await getContextFromURI(AVAX_PUBLIC_URL); | ||
const { context, feeState, pvmApi } = await setupEtnaExample(AVAX_PUBLIC_URL); | ||
|
||
const { utxos } = await pvmApi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] }); | ||
|
||
const tx = newBaseTx(context, [bech32ToBytes(P_CHAIN_ADDRESS)], utxos, [ | ||
TransferableOutput.fromNative(context.avaxAssetID, BigInt(0.1 * 1e9), [ | ||
bech32ToBytes(P_CHAIN_ADDRESS), | ||
]), | ||
]); | ||
const tx = pvm.newBaseTx( | ||
{ | ||
feeState, | ||
fromAddressesBytes: [utils.bech32ToBytes(P_CHAIN_ADDRESS)], | ||
outputs: [ | ||
TransferableOutput.fromNative( | ||
context.avaxAssetID, | ||
BigInt(SEND_AVAX_AMOUNT * 1e9), | ||
[utils.bech32ToBytes(P_CHAIN_ADDRESS)], | ||
), | ||
], | ||
utxos, | ||
}, | ||
context, | ||
); | ||
|
||
await addTxSignatures({ | ||
unsignedTx: tx, | ||
privateKeys: [hexToBuffer(PRIVATE_KEY)], | ||
privateKeys: [utils.hexToBuffer(PRIVATE_KEY)], | ||
}); | ||
|
||
return pvmapi.issueSignedTx(tx.getSignedTx()); | ||
return pvmApi.issueSignedTx(tx.getSignedTx()); | ||
}; | ||
|
||
main().then(console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,49 @@ | ||
import { PrimaryNetworkID } from '../../src/constants/networkIDs'; | ||
import { addTxSignatures } from '../../src/signer'; | ||
import { bech32ToBytes, hexToBuffer } from '../../src/utils'; | ||
import { getContextFromURI } from '../../src/vms/context'; | ||
import { PVMApi, newAddPermissionlessDelegatorTx } from '../../src/vms/pvm'; | ||
import { pvmapi } from '../chain_apis'; | ||
import { addTxSignatures, networkIDs, pvm, utils } from '../../src'; | ||
import { getEnvVars } from '../utils/getEnvVars'; | ||
import { setupEtnaExample } from './utils/etna-helper'; | ||
|
||
const AMOUNT_TO_DELEGATE_AVAX: number = 1; | ||
const DAYS_TO_DELEGATE: number = 14; | ||
|
||
const main = async () => { | ||
const { AVAX_PUBLIC_URL, P_CHAIN_ADDRESS, PRIVATE_KEY } = getEnvVars(); | ||
|
||
const { utxos } = await pvmapi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] }); | ||
const context = await getContextFromURI(AVAX_PUBLIC_URL); | ||
const startTime = await new PVMApi().getTimestamp(); | ||
const { context, feeState, pvmApi } = await setupEtnaExample(AVAX_PUBLIC_URL); | ||
|
||
const { utxos } = await pvmApi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] }); | ||
|
||
const startTime = await pvmApi.getTimestamp(); | ||
const startDate = new Date(startTime.timestamp); | ||
const start = BigInt(startDate.getTime() / 1000); | ||
const start: bigint = BigInt(startDate.getTime() / 1_000); | ||
|
||
const endTime = new Date(startTime.timestamp); | ||
endTime.setDate(endTime.getDate() + 21); | ||
const end = BigInt(endTime.getTime() / 1000); | ||
const nodeID = 'NodeID-HKLp5269LH8DcrLvHPc2PHjGczBQD3td4'; | ||
endTime.setDate(endTime.getDate() + DAYS_TO_DELEGATE); | ||
const end: bigint = BigInt(endTime.getTime() / 1_000); | ||
|
||
// TODO: Get this from an argument. | ||
const nodeId = 'NodeID-MqgFXT8JhorbEW2LpTDGePBBhv55SSp3M'; | ||
|
||
const tx = newAddPermissionlessDelegatorTx( | ||
const tx = pvm.newAddPermissionlessDelegatorTx( | ||
{ | ||
end, | ||
feeState, | ||
fromAddressesBytes: [utils.bech32ToBytes(P_CHAIN_ADDRESS)], | ||
nodeId, | ||
rewardAddresses: [utils.bech32ToBytes(P_CHAIN_ADDRESS)], | ||
start, | ||
subnetId: networkIDs.PrimaryNetworkID.toString(), | ||
utxos, | ||
weight: BigInt(AMOUNT_TO_DELEGATE_AVAX * 1e9), | ||
}, | ||
context, | ||
utxos, | ||
[bech32ToBytes(P_CHAIN_ADDRESS)], | ||
nodeID, | ||
PrimaryNetworkID.toString(), | ||
start, | ||
end, | ||
BigInt(1e9), | ||
[bech32ToBytes(P_CHAIN_ADDRESS)], | ||
); | ||
|
||
await addTxSignatures({ | ||
unsignedTx: tx, | ||
privateKeys: [hexToBuffer(PRIVATE_KEY)], | ||
privateKeys: [utils.hexToBuffer(PRIVATE_KEY)], | ||
}); | ||
|
||
return pvmapi.issueSignedTx(tx.getSignedTx()); | ||
return pvmApi.issueSignedTx(tx.getSignedTx()); | ||
}; | ||
|
||
main().then(console.log); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.