mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-14 11:48:12 +00:00
* openAPI: StorageRequestCreation: reward => pricePerByte, collateral => collateralPerByte * purchasing: reward => pricePerByte, collateral => collateralPerByte * Updates availabilities and reservations to use totalCollateral, minPricePerByte, and maxCollateralPerByte * Uses correct div operator when operating on UInt256 * proposal updating totalCollateral in availability * makes sure that reading currentCollateral happens before freeing slot * Updates naming * fixes tests: unit and contracts * uses feat/price-per-byte branch for codex-contracts-eth * temporarily disables integration tests on CI * introduces high level <<totalCollateral>> property for a cleaner external interface * updates integration tests * Applies review comments * Updates description of totalCollateral in SalesAvailability * updates codex-contracts-eth (price-per-byte)
85 lines
2.5 KiB
Nim
85 lines
2.5 KiB
Nim
import std/random
|
|
import std/sequtils
|
|
import pkg/libp2p
|
|
import pkg/nitro
|
|
import pkg/stint
|
|
import pkg/codex/rng
|
|
import pkg/codex/stores
|
|
import pkg/codex/blocktype as bt
|
|
import pkg/codex/sales
|
|
import pkg/codex/merkletree
|
|
import ../examples
|
|
|
|
export examples
|
|
|
|
proc example*(_: type EthAddress): EthAddress =
|
|
EthPrivateKey.random().toPublicKey.toAddress
|
|
|
|
proc example*(_: type UInt48): UInt48 =
|
|
# workaround for https://github.com/nim-lang/Nim/issues/17670
|
|
uint64.rand mod (UInt48.high + 1)
|
|
|
|
proc example*(_: type Wallet): Wallet =
|
|
Wallet.init(EthPrivateKey.random())
|
|
|
|
proc example*(_: type WalletRef): WalletRef =
|
|
WalletRef.new(EthPrivateKey.random())
|
|
|
|
proc example*(_: type SignedState): SignedState =
|
|
var wallet = Wallet.example
|
|
let hub, asset, receiver = EthAddress.example
|
|
let chainId, amount = UInt256.example
|
|
let nonce = UInt48.example
|
|
let channel = wallet.openLedgerChannel(hub, chainId, nonce, asset, amount).get
|
|
wallet.pay(channel, asset, receiver, amount).get
|
|
|
|
proc example*(_: type Pricing): Pricing =
|
|
Pricing(address: EthAddress.example, price: uint32.rand.u256)
|
|
|
|
proc example*(_: type bt.Block): bt.Block =
|
|
let length = rand(4096)
|
|
let bytes = newSeqWith(length, rand(uint8))
|
|
bt.Block.new(bytes).tryGet()
|
|
|
|
proc example*(_: type PeerId): PeerId =
|
|
let key = PrivateKey.random(Rng.instance[]).get
|
|
PeerId.init(key.getPublicKey().get).get
|
|
|
|
proc example*(_: type BlockExcPeerCtx): BlockExcPeerCtx =
|
|
BlockExcPeerCtx(id: PeerId.example)
|
|
|
|
proc example*(_: type Cid): Cid =
|
|
bt.Block.example.cid
|
|
|
|
proc example*(_: type MultiHash, mcodec = Sha256HashCodec): MultiHash =
|
|
let bytes = newSeqWith(256, rand(uint8))
|
|
MultiHash.digest($mcodec, bytes).tryGet()
|
|
|
|
proc example*(
|
|
_: type Availability, collateralPerByte = uint8.example.u256
|
|
): Availability =
|
|
let totalSize = uint16.example.u256
|
|
Availability.init(
|
|
totalSize = totalSize,
|
|
freeSize = uint16.example.u256,
|
|
duration = uint16.example.u256,
|
|
minPricePerBytePerSecond = uint8.example.u256,
|
|
totalCollateral = totalSize * collateralPerByte,
|
|
)
|
|
|
|
proc example*(_: type Reservation): Reservation =
|
|
Reservation.init(
|
|
availabilityId = AvailabilityId(array[32, byte].example),
|
|
size = uint16.example.u256,
|
|
slotId = SlotId.example,
|
|
)
|
|
|
|
proc example*(_: type MerkleProof): MerkleProof =
|
|
MerkleProof.init(3, @[MultiHash.example]).tryget()
|
|
|
|
proc example*(_: type Poseidon2Proof): Poseidon2Proof =
|
|
var example = MerkleProof[Poseidon2Hash, PoseidonKeysEnum]()
|
|
example.index = 123
|
|
example.path = @[1, 2, 3, 4].mapIt(it.toF)
|
|
example
|