Skip to content

Commit

Permalink
feat(jellyfish-network): add changi (#2143)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:
- Add changi network
- Update node to latest to fix regression issues

#### Which issue(s) does this PR fixes?:
<!--
(Optional) Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #

#### Additional comments?:

---------

Co-authored-by: canonbrother <w.canonbrother@gmail.com>
  • Loading branch information
pierregee and canonbrother authored Aug 25, 2023
1 parent 9daa1c1 commit adb503f
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 deletions.
5 changes: 3 additions & 2 deletions apps/legacy-api/src/pipes/NetworkValidationPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PipeTransform
} from '@nestjs/common'

export type SupportedNetwork = 'mainnet' | 'testnet' | 'devnet' | 'regtest'
export type SupportedNetwork = 'mainnet' | 'testnet' | 'devnet' | 'regtest' | 'changi'

@Injectable()
export class NetworkValidationPipe implements PipeTransform {
Expand All @@ -14,7 +14,8 @@ export class NetworkValidationPipe implements PipeTransform {
'mainnet',
'testnet',
'devnet',
'regtest'
'regtest',
'changi'
])

transform (value: any, metadata: ArgumentMetadata): any {
Expand Down
2 changes: 1 addition & 1 deletion apps/whale-api/src/app.configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function ENV_VALIDATION_SCHEMA (): any {
return Joi.object({
NODE_ENV: Joi.string().optional(),
WHALE_VERSION: Joi.string().optional(),
WHALE_NETWORK: Joi.string().valid('mainnet', 'testnet', 'regtest', 'devnet').default('regtest'),
WHALE_NETWORK: Joi.string().valid('mainnet', 'testnet', 'regtest', 'devnet', 'changi').default('regtest'),
WHALE_DEFID_URL: Joi.string().optional(),
WHALE_DATABASE_PROVIDER: Joi.string().optional(),
WHALE_DATABASE_LEVEL_LOCATION: Joi.string().optional()
Expand Down
6 changes: 6 additions & 0 deletions apps/whale-api/src/module.api/masternode.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const MasternodeConsensusParams = {
newActivationDelay: 1008,
resignDelay: 60,
newResignDelay: 2 * 1008
},
changi: {
activationDelay: 10,
newActivationDelay: 1008,
resignDelay: 60,
newResignDelay: 2 * 1008
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/jellyfish-network/__tests__/BitcoinJsLib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ it('should match RegTest network', () => {
expect(network.scriptHash).toStrictEqual(0xc4)
expect(network.messagePrefix).toStrictEqual('\x15Defi Signed Message:\n')
})

it('should match Changi network', () => {
const network = getNetworkBitcoinJsLib('changi')

expect(network.bech32).toStrictEqual('tf')
expect(network.bip32.public).toStrictEqual(0x043587cf)
expect(network.bip32.private).toStrictEqual(0x04358394)
expect(network.wif).toStrictEqual(0xef)
expect(network.pubKeyHash).toStrictEqual(0xf)
expect(network.scriptHash).toStrictEqual(0x80)
expect(network.messagePrefix).toStrictEqual('\x15Defi Signed Message:\n')
})
18 changes: 17 additions & 1 deletion packages/jellyfish-network/__tests__/Network.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Network, MainNet, RegTest, TestNet, DevNet, getNetwork } from '../src'
import { Network, MainNet, RegTest, TestNet, DevNet, Changi, getNetwork } from '../src'

it('should be exported', () => {
const network: Network = MainNet
Expand Down Expand Up @@ -26,6 +26,11 @@ describe('getNetwork', () => {
expect(getNetwork('regtest').name).toStrictEqual('regtest')
expect(getNetwork('regtest').bech32.hrp).toStrictEqual('bcrt')
})

it('should get changi', () => {
expect(getNetwork('changi').name).toStrictEqual('changi')
expect(getNetwork('changi').bech32.hrp).toStrictEqual('tf')
})
})

it('should match MainNet network', () => {
Expand Down Expand Up @@ -71,3 +76,14 @@ it('should match RegTest network', () => {
expect(RegTest.scriptHashPrefix).toStrictEqual(0xc4)
expect(RegTest.messagePrefix).toStrictEqual('\x15Defi Signed Message:\n')
})

it('should match Changi network', () => {
expect(Changi.name).toStrictEqual('changi')
expect(Changi.bech32.hrp).toStrictEqual('tf')
expect(Changi.bip32.publicPrefix).toStrictEqual(0x043587cf)
expect(Changi.bip32.privatePrefix).toStrictEqual(0x04358394)
expect(Changi.wifPrefix).toStrictEqual(0xef)
expect(Changi.pubKeyHashPrefix).toStrictEqual(0xf)
expect(Changi.scriptHashPrefix).toStrictEqual(0x80)
expect(Changi.messagePrefix).toStrictEqual('\x15Defi Signed Message:\n')
})
20 changes: 17 additions & 3 deletions packages/jellyfish-network/src/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type NetworkName = Network['name']
* They can be found in DeFiCh/ain project in file chainparams.cpp, under base58Prefixes
*/
export interface Network {
name: 'mainnet' | 'testnet' | 'regtest' | 'devnet'
name: 'mainnet' | 'testnet' | 'regtest' | 'devnet' | 'changi'
bech32: {
/** bech32 human readable part */
hrp: 'df' | 'tf' | 'bcrt'
Expand Down Expand Up @@ -48,6 +48,8 @@ export function getNetwork (network: NetworkName): Network {
return DevNet
case 'regtest':
return RegTest
case 'changi':
return Changi
default:
throw new Error(`${network as string} network not found`)
}
Expand Down Expand Up @@ -104,8 +106,8 @@ export const DevNet: Network = {
...TestNet,
name: 'devnet',
ports: {
rpc: 20554,
p2p: 20555
rpc: 21554,
p2p: 21555
}
}

Expand All @@ -130,3 +132,15 @@ export const RegTest: Network = {
p2p: 19555
}
}

/**
* Changi specific DeFi configuration.
*/
export const Changi: Network = {
...TestNet,
name: 'changi',
ports: {
rpc: 20554,
p2p: 20555
}
}
2 changes: 1 addition & 1 deletion packages/ocean-api-client/src/OceanApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface OceanApiClientOptions {
/**
* Network that ocean client is configured to
*/
network?: 'mainnet' | 'testnet' | 'devnet' | 'regtest' | string
network?: 'mainnet' | 'testnet' | 'devnet' | 'regtest' | 'changi' | string
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/testcontainers/src/containers/DeFiDContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NativeChainRpc } from '../index'
/**
* Types of network as per https://github.com/DeFiCh/ain/blob/bc231241/src/chainparams.cpp#L825-L836
*/
type Network = 'mainnet' | 'testnet' | 'devnet' | 'regtest'
type Network = 'mainnet' | 'testnet' | 'devnet' | 'regtest' | 'changi'

/**
* Mandatory options to start defid with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export class NativeChainContainer extends GenericContainer {
'-rpcbind=0.0.0.0',
'-rpcworkqueue=512'
],
changi: [
'-changi=1'
],
testnet: [
'-testnet=1'
],
Expand Down

0 comments on commit adb503f

Please sign in to comment.