Skip to content

Commit d260915

Browse files
authored
enable styleCheck:usages (#49)
1 parent 9437183 commit d260915

File tree

9 files changed

+43
-39
lines changed

9 files changed

+43
-39
lines changed

tests/test.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ contract NumberStorage {
4242
}
4343
]#
4444
contract(NumberStorage):
45-
proc setNumber(number: Uint256)
46-
proc getNumber(): Uint256 {.view.}
45+
proc setNumber(number: UInt256)
46+
proc getNumber(): UInt256 {.view.}
4747

4848
const NumberStorageCode = "6060604052341561000f57600080fd5b60bb8061001d6000396000f30060606040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fb5c1cb8114604d578063f2c9ecd8146062575b600080fd5b3415605757600080fd5b60606004356084565b005b3415606c57600080fd5b60726089565b60405190815260200160405180910390f35b600055565b600054905600a165627a7a7230582023e722f35009f12d5698a4ab22fb9d55a6c0f479fc43875c65be46fbdd8db4310029"
4949

@@ -73,9 +73,9 @@ contract MetaCoin {
7373
}
7474
]#
7575
contract(MetaCoin):
76-
proc sendCoin(receiver: Address, amount: Uint256): Bool
77-
proc getBalance(address: Address): Uint256 {.view.}
78-
proc Transfer(fromAddr, toAddr: indexed[Address], value: Uint256) {.event.}
76+
proc sendCoin(receiver: Address, amount: UInt256): Bool
77+
proc getBalance(address: Address): UInt256 {.view.}
78+
proc Transfer(fromAddr, toAddr: indexed[Address], value: UInt256) {.event.}
7979
proc BlaBla(fromAddr: indexed[Address]) {.event.}
8080

8181
const MetaCoinCode = "608060405234801561001057600080fd5b5032600090815260208190526040902061271090556101c2806100346000396000f30060806040526004361061004b5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166390b98a118114610050578063f8b2cb4f14610095575b600080fd5b34801561005c57600080fd5b5061008173ffffffffffffffffffffffffffffffffffffffff600435166024356100d5565b604080519115158252519081900360200190f35b3480156100a157600080fd5b506100c373ffffffffffffffffffffffffffffffffffffffff6004351661016e565b60408051918252519081900360200190f35b336000908152602081905260408120548211156100f457506000610168565b336000818152602081815260408083208054879003905573ffffffffffffffffffffffffffffffffffffffff871680845292819020805487019055805186815290519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a35060015b92915050565b73ffffffffffffffffffffffffffffffffffffffff16600090815260208190526040902054905600a165627a7a72305820000313ec0ebbff4ffefbe79d615d0ab019d8566100c40eb95a4eee617a87d1090029"
@@ -149,7 +149,7 @@ suite "Contracts":
149149
var notificationsReceived = 0
150150

151151
let s = await ns.subscribe(Transfer) do (
152-
fromAddr, toAddr: Address, value: Uint256)
152+
fromAddr, toAddr: Address, value: UInt256)
153153
{.raises: [Defect], gcsafe.}:
154154
try:
155155
echo "onTransfer: ", fromAddr, " transferred ", value, " to ", toAddr

tests/test_logs.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ contract LoggerContract {
2121
}
2222
]#
2323
contract(LoggerContract):
24-
proc MyEvent(sender: Address, number: Uint256) {.event.}
25-
proc invoke(value: Uint256)
24+
proc MyEvent(sender: Address, number: UInt256) {.event.}
25+
proc invoke(value: UInt256)
2626

2727
const LoggerContractCode = "6080604052348015600f57600080fd5b5060bc8061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80632b30d2b814602d575b600080fd5b604760048036036020811015604157600080fd5b50356049565b005b604080513381526020810183905281517fdf50c7bb3b25f812aedef81bc334454040e7b27e27de95a79451d663013b7e17929181900390910190a15056fea265627a7a723058202ed7f5086297d2a49fbe359f4e489a007b69eb5077f5c76328bffdb63f164b4b64736f6c63430005090032"
2828

@@ -67,7 +67,7 @@ suite "Logs":
6767
var notificationsReceived = 0
6868

6969
let s = await ns.subscribe(MyEvent, %*{"fromBlock": "0x0"}) do (
70-
sender: Address, value: Uint256)
70+
sender: Address, value: UInt256)
7171
{.raises: [Defect], gcsafe.}:
7272
try:
7373
echo "onEvent: ", sender, " value ", value

tests/test_signed_tx.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ contract NumberStorage {
1919
}
2020
]#
2121
contract(NumberStorage):
22-
proc setNumber(number: Uint256)
23-
proc getNumber(): Uint256 {.view.}
22+
proc setNumber(number: UInt256)
23+
proc getNumber(): UInt256 {.view.}
2424

2525
const NumberStorageCode = "6060604052341561000f57600080fd5b60bb8061001d6000396000f30060606040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fb5c1cb8114604d578063f2c9ecd8146062575b600080fd5b3415605757600080fd5b60606004356084565b005b3415606c57600080fd5b60726089565b60405190815260200160405180910390f35b600055565b600054905600a165627a7a7230582023e722f35009f12d5698a4ab22fb9d55a6c0f479fc43875c65be46fbdd8db4310029"
2626

web3.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type
4949
web3: Web3
5050
data: string
5151
to: Address
52-
value: Uint256
52+
value: UInt256
5353

5454
ContractCall*[T] = ref object of ContractCallBase
5555

@@ -405,7 +405,7 @@ macro contract*(cname: untyped, body: untyped): untyped =
405405
`encoder`
406406
return initContractCall[`output`](
407407
`senderName`.web3,
408-
($keccak_256.digest(`signature`))[0..<8].toLower & `encodedParams`,
408+
($keccak256.digest(`signature`))[0..<8].toLower & `encodedParams`,
409409
`senderName`.contractAddress)
410410

411411
result.add procDef
@@ -681,4 +681,4 @@ proc subscribe*(s: Sender, t: typedesc, cb: proc): Future[Subscription] {.inline
681681
subscribe(s, t, newJObject(), cb, SubscriptionErrorHandler nil)
682682

683683
proc `$`*(b: Bool): string =
684-
$(Stint[256](b))
684+
$(StInt[256](b))

web3.nimble

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description = "This is the humble begginings of library similar to web3.[js|py
66
license = "MIT or Apache License 2.0"
77

88
### Dependencies
9-
requires "nim >= 0.18.0"
9+
requires "nim >= 1.2.0"
1010
requires "chronicles"
1111
requires "chronos"
1212
requires "eth"
@@ -22,7 +22,11 @@ proc test(args, path: string) =
2222
if not dirExists "build":
2323
mkDir "build"
2424
exec "nim " & getEnv("TEST_LANG", "c") & " " & getEnv("NIMFLAGS") & " " & args &
25-
" --outdir:build -r --hints:off --warnings:off --skipParentCfg " & path
25+
" --outdir:build -r --skipParentCfg" &
26+
" --warning[ObservableStores]:off --warning[GcUnsafe2]:off" &
27+
" --styleCheck:usages --styleCheck:hint" &
28+
" --hint[XDeclaredButNotUsed]:off --hint[Processing]:off " &
29+
path
2630

2731

2832
### tasks

web3/conversions.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ proc fromJson*(n: JsonNode, argName: string, result: var ref UInt256) =
2727
new result
2828
result[] = hexStr.parse(StUint[256], 16) # TODO: Handle errors
2929

30-
proc bytesFromJson(n: JsonNode, argName: string, result: var openarray[byte]) =
30+
proc bytesFromJson(n: JsonNode, argName: string, result: var openArray[byte]) =
3131
n.kind.expect(JString, argName)
3232
let hexStr = n.getStr()
3333
if hexStr.len != result.len * 2 + 2: # including "0x"
@@ -98,7 +98,7 @@ proc `%`*(v: Address): JsonNode =
9898
proc `%`*(v: TypedTransaction): JsonNode =
9999
result = %("0x" & distinctBase(v).toHex)
100100

101-
proc writeHexValue(w: JsonWriter, v: openarray[byte]) =
101+
proc writeHexValue(w: JsonWriter, v: openArray[byte]) =
102102
w.stream.write "\"0x"
103103
w.stream.writeHex v
104104
w.stream.write "\""
@@ -140,7 +140,7 @@ proc `$`*(v: DynamicBytes): string {.inline.} =
140140
"0x" & toHex(v)
141141

142142
proc `%`*(x: EthSend): JsonNode =
143-
result = newJobject()
143+
result = newJObject()
144144
result["from"] = %x.source
145145
if x.to.isSome:
146146
result["to"] = %x.to.unsafeGet
@@ -156,7 +156,7 @@ proc `%`*(x: EthSend): JsonNode =
156156
result["nonce"] = %x.nonce.unsafeGet
157157

158158
proc `%`*(x: EthCall): JsonNode =
159-
result = newJobject()
159+
result = newJObject()
160160
result["to"] = %x.to
161161
if x.source.isSome:
162162
result["source"] = %x.source.unsafeGet
@@ -173,7 +173,7 @@ proc `%`*(x: byte): JsonNode =
173173
%x.int
174174

175175
proc `%`*(x: FilterOptions): JsonNode =
176-
result = newJobject()
176+
result = newJObject()
177177
if x.fromBlock.isSome:
178178
result["fromBlock"] = %x.fromBlock.unsafeGet
179179
if x.toBlock.isSome:

web3/encoding.nim

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import
77
type
88
EncodeResult* = tuple[dynamic: bool, data: string]
99

10-
func encode*[bits: static[int]](x: Stuint[bits]): EncodeResult =
11-
## Encodes a `Stuint` to a textual representation for use in the JsonRPC
10+
func encode*[bits: static[int]](x: StUint[bits]): EncodeResult =
11+
## Encodes a `StUint` to a textual representation for use in the JsonRPC
1212
## `sendTransaction` call.
1313
(dynamic: false, data: '0'.repeat((256 - bits) div 4) & x.dumpHex)
1414

15-
func encode*[bits: static[int]](x: Stint[bits]): EncodeResult =
16-
## Encodes a `Stint` to a textual representation for use in the JsonRPC
15+
func encode*[bits: static[int]](x: StInt[bits]): EncodeResult =
16+
## Encodes a `StInt` to a textual representation for use in the JsonRPC
1717
## `sendTransaction` call.
1818
(dynamic: false,
1919
data:
@@ -23,25 +23,25 @@ func encode*[bits: static[int]](x: Stint[bits]): EncodeResult =
2323
'0'.repeat((256 - bits) div 4) & x.dumpHex
2424
)
2525

26-
func decode*(input: string, offset: int, to: var Stuint): int =
26+
func decode*(input: string, offset: int, to: var StUint): int =
2727
let meaningfulLen = to.bits div 8 * 2
2828
to = type(to).fromHex(input[offset .. offset + meaningfulLen - 1])
2929
meaningfulLen
3030

31-
func decode*[N](input: string, offset: int, to: var Stint[N]): int =
31+
func decode*[N](input: string, offset: int, to: var StInt[N]): int =
3232
let meaningfulLen = N div 8 * 2
3333
fromHex(input[offset .. offset + meaningfulLen], to)
3434
meaningfulLen
3535

36-
func fixedEncode(a: openarray[byte]): EncodeResult =
36+
func fixedEncode(a: openArray[byte]): EncodeResult =
3737
var padding = a.len mod 32
3838
if padding != 0: padding = 32 - padding
3939
result = (dynamic: false, data: "00".repeat(padding) & byteutils.toHex(a))
4040

4141
func encode*[N](b: FixedBytes[N]): EncodeResult = fixedEncode(array[N, byte](b))
4242
func encode*(b: Address): EncodeResult = fixedEncode(array[20, byte](b))
4343

44-
func decodeFixed(input: string, offset: int, to: var openarray[byte]): int =
44+
func decodeFixed(input: string, offset: int, to: var openArray[byte]): int =
4545
let meaningfulLen = to.len * 2
4646
var padding = to.len mod 32
4747
if padding != 0: padding = (32 - padding) * 2
@@ -55,7 +55,7 @@ func decode*[N](input: string, offset: int, to: var FixedBytes[N]): int {.inline
5555
func decode*(input: string, offset: int, to: var Address): int {.inline.} =
5656
decodeFixed(input, offset, array[20, byte](to))
5757

58-
func encodeDynamic(v: openarray[byte]): EncodeResult =
58+
func encodeDynamic(v: openArray[byte]): EncodeResult =
5959
result.dynamic = true
6060
result.data = v.len.toHex(64).toLower
6161
for y in v:
@@ -86,18 +86,18 @@ macro makeTypeEnum(): untyped =
8686
identInt = newIdentNode("Int" & $i)
8787
if ceil(log2(i.float)) == floor(log2(i.float)):
8888
lastpow2 = i
89-
if i notin {256, 125}: # Int/Uint256/128 are already defined in stint. No need to repeat.
89+
if i notin {256, 125}: # Int/UInt256/128 are already defined in stint. No need to repeat.
9090
result.add quote do:
9191
type
92-
`identUint`* = Stuint[`lastpow2`]
93-
`identInt`* = Stint[`lastpow2`]
92+
`identUint`* = StUint[`lastpow2`]
93+
`identInt`* = StInt[`lastpow2`]
9494
let
9595
identUint = ident("Uint")
9696
identInt = ident("Int")
9797
identBool = ident("Bool")
9898
result.add quote do:
9999
type
100-
`identUint`* = Uint256
100+
`identUint`* = UInt256
101101
`identInt`* = Int256
102102
`identBool`* = distinct Int256
103103

@@ -139,7 +139,7 @@ macro makeTypeEnum(): untyped =
139139
result.add quote do:
140140
type
141141
`identFixed`* = distinct Int128
142-
`identUfixed`* = distinct Uint128
142+
`identUfixed`* = distinct UInt128
143143
for i in 1..256:
144144
let
145145
identBytes = ident("Bytes" & $i)
@@ -191,7 +191,7 @@ func encode*(x: seq[Encodable]): EncodeResult =
191191
result.data &= data
192192

193193
func decode*[T](input: string, to: seq[T]): seq[T] =
194-
var count = input[0..64].decode(Stuint)
194+
var count = input[0..64].decode(StUint)
195195
result = newSeq[T](count)
196196
for i in 0..count:
197197
result[i] = input[i*64 .. (i+1)*64].decode(T)

web3/engine_api_types.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type
4242

4343
# https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.8/src/engine/specification.md#transitionconfigurationv1
4444
TransitionConfigurationV1* = object
45-
terminalTotalDifficulty*: Uint256
45+
terminalTotalDifficulty*: UInt256
4646
terminalBlockHash*: BlockHash
4747
terminalBlockNumber*: Quantity
4848

web3/ethtypes.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type
3838
to*: Option[Address] # (optional when creating new contract) the address the transaction is directed to.
3939
gas*: Option[Quantity] # (optional, default: 90000) integer of the gas provided for the transaction execution. It will return unused gas.
4040
gasPrice*: Option[int] # (optional, default: To-Be-Determined) integer of the gasPrice used for each paid gas.
41-
value*: Option[Uint256] # (optional) integer of the value sent with this transaction.
41+
value*: Option[UInt256] # (optional) integer of the value sent with this transaction.
4242
data*: string # the compiled code of a contract OR the hash of the invoked method signature and encoded parameters. For details see Ethereum Contract ABI.
4343
nonce*: Option[Nonce] # (optional) integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce
4444

@@ -291,4 +291,4 @@ template len*(data: DynamicBytes): int =
291291
len(distinctBase data)
292292

293293
func `$`*[minLen, maxLen](data: DynamicBytes[minLen, maxLen]): string =
294-
"0x" & byteutils.toHex(distinctbase(data))
294+
"0x" & byteutils.toHex(distinctBase(data))

0 commit comments

Comments
 (0)