fix(messenger):fix unexpected open multiple endpoints

staking
neeboo 5 years ago
parent 299af73fe5
commit 6759acb035
  1. 4
      packages/harmony-core/src/harmony.ts
  2. 4
      packages/harmony-core/src/harmonyExtension.ts
  3. 8
      packages/harmony-crypto/src/address.ts
  4. 16
      packages/harmony-network/src/messenger/messenger.ts

@ -83,8 +83,8 @@ export class Harmony extends utils.HarmonyCore {
this.messenger.shardProviders.set(shardID, {
current: shard.current !== undefined ? shard.current : false,
shardID,
http: new HttpProvider(shard.http),
ws: new WSProvider(shard.ws),
http: shard.http,
ws: shard.ws,
});
}
this.setMessenger(this.messenger);

@ -152,8 +152,8 @@ export class HarmonyExtension {
this.messenger.shardProviders.set(shardID, {
current: shard.current !== undefined ? shard.current : false,
shardID,
http: new HttpProvider(shard.http),
ws: new WSProvider(shard.ws),
http: shard.http,
ws: shard.ws,
});
}
this.setMessenger(this.messenger);

@ -1,8 +1,4 @@
import {
isAddress,
isBech32Address,
isBech32TestNetAddress,
} from '@harmony-js/utils';
import { isAddress, isBech32Address, isBech32TestNetAddress } from '@harmony-js/utils';
import { toChecksumAddress } from './keyTool';
import { fromBech32, toBech32, HRP, tHRP } from './bech32';
@ -71,7 +67,7 @@ export class HarmonyAddress {
return fromB32TestNet.replace('0x', '').toLowerCase();
}
throw new Error(`${addr} is valid address format`);
throw new Error(`"${addr}" is an invalid address format`);
}
}

@ -10,8 +10,8 @@ import { SubscribeReturns, ShardingItem } from '../types';
export interface ShardingProvider {
current: boolean;
shardID: number;
http: HttpProvider;
ws: WSProvider;
http: string;
ws: string;
}
/**
@ -275,8 +275,8 @@ class Messenger extends HarmonyCore {
this.shardProviders.set(shardID, {
current: shard.current,
shardID,
http: new HttpProvider(shard.http),
ws: new WSProvider(shard.ws),
http: shard.http,
ws: shard.ws,
});
}
}
@ -287,7 +287,9 @@ class Messenger extends HarmonyCore {
getShardProvider(shardID: number): HttpProvider | WSProvider {
const provider = this.shardProviders.get(shardID);
if (provider) {
return this.provider instanceof HttpProvider ? provider.http : provider.ws;
return this.provider instanceof HttpProvider
? new HttpProvider(provider.http)
: new WSProvider(provider.ws);
}
return this.provider;
}
@ -295,8 +297,8 @@ class Messenger extends HarmonyCore {
for (const shard of this.shardProviders) {
if (
shard[1].current === true ||
shard[1].http.url === this.provider.url ||
shard[1].ws.url === this.provider.url
shard[1].http === this.provider.url ||
shard[1].ws === this.provider.url
) {
return shard[1].shardID;
}

Loading…
Cancel
Save