This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for additional methods used by js-lotus-client-workshop
- Loading branch information
Showing
5 changed files
with
296 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { | ||
SerializableObject, | ||
SerializedObject, | ||
DeserializedObject, | ||
Definitions | ||
} from "./serializable-object"; | ||
import { Address, SerializedAddress } from "./address"; | ||
|
||
type MinerInfoConfig = { | ||
properties: { | ||
owner: { | ||
type: Address; | ||
serializedType: SerializedAddress; | ||
serializedName: "Owner"; | ||
}; | ||
worker: { | ||
type: Address; | ||
serializedType: SerializedAddress; | ||
serializedName: "Worker"; | ||
}; | ||
newWorker: { | ||
type: Address; | ||
serializedType: SerializedAddress; | ||
serializedName: "NewWorker"; | ||
}; | ||
controlAddresses: { | ||
type: Address[]; | ||
serializedType: SerializedAddress[]; | ||
serializedName: "ControlAddresses"; | ||
}; | ||
workerChangeEpoch: { | ||
type: bigint; | ||
serializedType: string; | ||
serializedName: "WorkerChangeEpoch"; | ||
}; | ||
peerId: { | ||
type: string; | ||
serializedType: string; | ||
serializedName: "PeerId"; | ||
}; | ||
multiaddrs: { | ||
type: Uint8Array[]; | ||
serializedType: Uint8Array[]; | ||
serializedName: "Multiaddrs"; | ||
}; | ||
sealProofType: { | ||
type: bigint; | ||
serializedType: string; | ||
serializedName: "SealProofType"; | ||
}; | ||
sectorSize: { | ||
type: bigint; | ||
serializedType: string; | ||
serializedName: "SectorSize"; | ||
}; | ||
windowPoStPartitionSectors: { | ||
type: bigint; | ||
serializedType: string; | ||
serializedName: "WindowPoStPartitionSectors"; | ||
}; | ||
consensusFaultElapsed: { | ||
type: bigint; | ||
serializedType: string; | ||
serializedName: "ConsensusFaultElapsed"; | ||
}; | ||
}; | ||
}; | ||
|
||
class MinerInfo | ||
extends SerializableObject<MinerInfoConfig> | ||
implements DeserializedObject<MinerInfoConfig> { | ||
get config(): Definitions<MinerInfoConfig> { | ||
return { | ||
owner: { | ||
serializedName: "Owner", | ||
defaultValue: Address.random() | ||
}, | ||
worker: { | ||
serializedName: "Worker", | ||
defaultValue: Address.random() | ||
}, | ||
newWorker: { | ||
serializedName: "NewWorker", | ||
defaultValue: Address.random() | ||
}, | ||
controlAddresses: { | ||
serializedName: "ControlAddresses", | ||
defaultValue: [Address.random()] | ||
}, | ||
workerChangeEpoch: { | ||
serializedName: "WorkerChangeEpoch", | ||
defaultValue: config => (config ? BigInt(config) : 0n) | ||
}, | ||
peerId: { | ||
serializedName: "PeerId", | ||
defaultValue: "0" | ||
}, | ||
multiaddrs: { | ||
serializedName: "Multiaddrs", | ||
defaultValue: [new Uint8Array()] | ||
}, | ||
sealProofType: { | ||
serializedName: "SealProofType", | ||
defaultValue: config => (config ? BigInt(config) : 0n) // not sure what to put here | ||
}, | ||
sectorSize: { | ||
serializedName: "SectorSize", | ||
defaultValue: 18446744073709551615n // max from https://bit.ly/2XJItAg | ||
}, | ||
windowPoStPartitionSectors: { | ||
serializedName: "WindowPoStPartitionSectors", | ||
defaultValue: config => (config ? BigInt(config) : 0n) // not sure what to put here | ||
}, | ||
consensusFaultElapsed: { | ||
serializedName: "ConsensusFaultElapsed", | ||
defaultValue: config => (config ? BigInt(config) : 0n) // not sure what to put here | ||
} | ||
}; | ||
} | ||
|
||
owner: Address; | ||
worker: Address; | ||
newWorker: Address; | ||
controlAddresses: Address[]; | ||
workerChangeEpoch: bigint; | ||
peerId: string; | ||
multiaddrs: Uint8Array[]; | ||
sealProofType: bigint; | ||
sectorSize: bigint; | ||
windowPoStPartitionSectors: bigint; | ||
consensusFaultElapsed: bigint; | ||
} | ||
|
||
type SerializedMinerInfo = SerializedObject<MinerInfoConfig>; | ||
|
||
export { MinerInfo, SerializedMinerInfo }; |
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,58 @@ | ||
import { | ||
SerializableObject, | ||
SerializedObject, | ||
DeserializedObject, | ||
Definitions | ||
} from "./serializable-object"; | ||
import { CID, SerializedCID } from "./cid"; | ||
import { Miner, SerializedMiner } from "./miner"; | ||
|
||
type RetrievalPeerConfig = { | ||
properties: { | ||
address: { | ||
type: Miner; | ||
serializedType: SerializedMiner; | ||
serializedName: "Address"; | ||
}; | ||
id: { | ||
type: string; | ||
serializedType: string; | ||
serializedName: "ID"; | ||
}; | ||
pieceCID: { | ||
type: CID; | ||
serializedType: SerializedCID; | ||
serializedName: "PieceCID"; | ||
}; | ||
}; | ||
}; | ||
|
||
class RetrievalPeer | ||
extends SerializableObject<RetrievalPeerConfig> | ||
implements DeserializedObject<RetrievalPeerConfig> { | ||
get config(): Definitions<RetrievalPeerConfig> { | ||
return { | ||
address: { | ||
serializedName: "Address", | ||
defaultValue: options => new Miner(options) | ||
}, | ||
id: { | ||
serializedName: "ID", | ||
defaultValue: "0" | ||
}, | ||
pieceCID: { | ||
serializedName: "PieceCID", | ||
defaultValue: options => | ||
new CID(options || "Piece CIDs are not supported in Ganache") | ||
} | ||
}; | ||
} | ||
|
||
address: Miner; | ||
id: string; | ||
pieceCID: CID; | ||
} | ||
|
||
type SerializedRetrievalPeer = SerializedObject<RetrievalPeerConfig>; | ||
|
||
export { RetrievalPeer, SerializedRetrievalPeer }; |
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,74 @@ | ||
import { | ||
SerializableObject, | ||
DeserializedObject, | ||
SerializedObject, | ||
Definitions | ||
} from "./serializable-object"; | ||
import { $INLINE_JSON } from "ts-transformer-inline-file"; | ||
|
||
const { version: GanacheFilecoinVersion } = $INLINE_JSON("../../package.json"); | ||
|
||
function createBinarySemverVersion(version: string): number { | ||
const versionParts = version.split("."); | ||
|
||
const majorVersion = | ||
versionParts.length > 0 ? parseInt(versionParts[0], 10) : 0; | ||
const minorVersion = | ||
versionParts.length > 1 ? parseInt(versionParts[1], 10) : 0; | ||
const patchVersion = | ||
versionParts.length > 2 ? parseInt(versionParts[2], 10) : 0; | ||
|
||
const binaryVersion = | ||
(majorVersion << 16) | (minorVersion << 8) | patchVersion; | ||
|
||
return binaryVersion; | ||
} | ||
|
||
interface VersionConfig { | ||
properties: { | ||
version: { | ||
type: string; | ||
serializedType: string; | ||
serializedName: "Version"; | ||
}; | ||
apiVersion: { | ||
type: number; | ||
serializedType: number; | ||
serializedName: "APIVersion"; | ||
}; | ||
blockDelay: { | ||
type: bigint; | ||
serializedType: string; | ||
serializedName: "BlockDelay"; | ||
}; | ||
}; | ||
} | ||
|
||
class Version | ||
extends SerializableObject<VersionConfig> | ||
implements DeserializedObject<VersionConfig> { | ||
get config(): Definitions<VersionConfig> { | ||
return { | ||
version: { | ||
serializedName: "Version", | ||
defaultValue: `@ganache/filecoin v${GanacheFilecoinVersion}` | ||
}, | ||
apiVersion: { | ||
serializedName: "APIVersion", | ||
defaultValue: createBinarySemverVersion("0.0.1") // TODO: not sure what to put here | ||
}, | ||
blockDelay: { | ||
serializedName: "BlockDelay", | ||
defaultValue: 0n | ||
} | ||
}; | ||
} | ||
|
||
version: string; | ||
apiVersion: number; | ||
blockDelay: bigint; | ||
} | ||
|
||
type SerializedVersion = SerializedObject<VersionConfig>; | ||
|
||
export { Version, SerializedVersion }; |