-
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.
…#890) * feat: add DisableSubnetValidatorTx * feat: add SetSubnetValidatorWeightTx * fix: add missing typeguard usage
- Loading branch information
1 parent
683b56f
commit d80b456
Showing
17 changed files
with
578 additions
and
45 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { testPVMCodec } from '../../fixtures/codec'; | ||
import { | ||
disableSubnetValidatorTx, | ||
disableSubnetValidatorTxBytes, | ||
} from '../../fixtures/pvm'; | ||
import { testSerialization } from '../../fixtures/utils/serializable'; | ||
import { DisableSubnetValidatorTx } from './disableSubnetValidatorTx'; | ||
|
||
testSerialization( | ||
'DisableSubnetValidatorTx', | ||
DisableSubnetValidatorTx, | ||
disableSubnetValidatorTx, | ||
disableSubnetValidatorTxBytes, | ||
testPVMCodec, | ||
); |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { concatBytes } from '@noble/hashes/utils'; | ||
import { pack, unpack } from '../../utils/struct'; | ||
import { BaseTx } from '../avax/baseTx'; | ||
import { Codec } from '../codec/codec'; | ||
import { serializable, type Serializable } from '../common/types'; | ||
import { TypeSymbols } from '../constants'; | ||
import { Id } from '../fxs/common'; | ||
import { PVMTx } from './abstractTx'; | ||
import type { Input } from '../fxs/secp256k1'; | ||
|
||
@serializable() | ||
export class DisableSubnetValidatorTx extends PVMTx { | ||
_type = TypeSymbols.DisableSubnetValidatorTx; | ||
|
||
constructor( | ||
public readonly baseTx: BaseTx, | ||
public readonly validationId: Id, | ||
public readonly disableAuth: Serializable, | ||
) { | ||
super(); | ||
} | ||
|
||
static fromBytes( | ||
bytes: Uint8Array, | ||
codec: Codec, | ||
): [disableSubnetValidatorTx: DisableSubnetValidatorTx, rest: Uint8Array] { | ||
const [baseTx, validationId, disableAuth, rest] = unpack( | ||
bytes, | ||
[BaseTx, Id, Codec], | ||
codec, | ||
); | ||
return [ | ||
new DisableSubnetValidatorTx(baseTx, validationId, disableAuth), | ||
rest, | ||
]; | ||
} | ||
|
||
toBytes(codec: Codec) { | ||
return concatBytes( | ||
pack([this.baseTx, this.validationId], codec), | ||
codec.PackPrefix(this.disableAuth), | ||
); | ||
} | ||
|
||
getDisableAuth() { | ||
return this.disableAuth as Input; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { testPVMCodec } from '../../fixtures/codec'; | ||
import { | ||
setSubnetValidatorWeightTx, | ||
setSubnetValidatorWeightTxBytes, | ||
} from '../../fixtures/pvm'; | ||
import { testSerialization } from '../../fixtures/utils/serializable'; | ||
import { SetSubnetValidatorWeightTx } from './setSubnetValidatorWeightTx'; | ||
|
||
testSerialization( | ||
'SetSubnetValidatorWeightTx', | ||
SetSubnetValidatorWeightTx, | ||
setSubnetValidatorWeightTx, | ||
setSubnetValidatorWeightTxBytes, | ||
testPVMCodec, | ||
); |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { pack, unpack } from '../../utils/struct'; | ||
import { BaseTx } from '../avax/baseTx'; | ||
import type { Codec } from '../codec'; | ||
import { serializable } from '../common/types'; | ||
import { TypeSymbols } from '../constants'; | ||
import { Bytes } from '../primitives'; | ||
import { PVMTx } from './abstractTx'; | ||
|
||
@serializable() | ||
export class SetSubnetValidatorWeightTx extends PVMTx { | ||
_type = TypeSymbols.SetSubnetValidatorWeightTx; | ||
|
||
constructor(public readonly baseTx: BaseTx, public readonly message: Bytes) { | ||
super(); | ||
} | ||
|
||
static fromBytes( | ||
bytes: Uint8Array, | ||
codec: Codec, | ||
): [SetSubnetValidatorWeightTx, Uint8Array] { | ||
const [baseTx, message, rest] = unpack(bytes, [BaseTx, Bytes], codec); | ||
|
||
return [new SetSubnetValidatorWeightTx(baseTx, message), rest]; | ||
} | ||
|
||
toBytes(codec: Codec): Uint8Array { | ||
return pack([this.baseTx, this.message], codec); | ||
} | ||
} |
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
Oops, something went wrong.