Skip to content

Commit 617ea5b

Browse files
committed
refactor: support go 1.24 with newtypes
1 parent e6448b2 commit 617ea5b

File tree

6 files changed

+500
-310
lines changed

6 files changed

+500
-310
lines changed

cgo/bls.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,59 @@ package cgo
99
import "C"
1010

1111
func Hash(message SliceRefUint8) *[96]byte {
12-
resp := C.hash(message)
12+
resp := (*ByteArray96)(C.hash((C.slice_ref_uint8_t)(message)))
1313
defer resp.destroy()
1414
return resp.copyAsArray()
1515
}
1616

1717
func Aggregate(flattenedSignatures SliceRefUint8) *[96]byte {
18-
resp := C.aggregate(flattenedSignatures)
18+
resp := (*ByteArray96)(C.aggregate((C.slice_ref_uint8_t)(flattenedSignatures)))
1919
defer resp.destroy()
2020
return resp.copyAsArray()
2121
}
2222

2323
func Verify(signature SliceRefUint8, flattenedDigests SliceRefUint8, flattenedPublicKeys SliceRefUint8) bool {
24-
resp := C.verify(signature, flattenedDigests, flattenedPublicKeys)
24+
resp := C.verify((C.slice_ref_uint8_t)(signature),
25+
(C.slice_ref_uint8_t)(flattenedDigests),
26+
(C.slice_ref_uint8_t)(flattenedPublicKeys))
2527
return bool(resp)
2628
}
2729

2830
func HashVerify(signature SliceRefUint8, flattenedMessages SliceRefUint8, messageSizes SliceRefUint, flattenedPublicKeys SliceRefUint8) bool {
29-
resp := C.hash_verify(signature, flattenedMessages, messageSizes, flattenedPublicKeys)
31+
resp := C.hash_verify((C.slice_ref_uint8_t)(signature),
32+
(C.slice_ref_uint8_t)(flattenedMessages),
33+
(C.slice_ref_size_t)(messageSizes),
34+
(C.slice_ref_uint8_t)(flattenedPublicKeys))
3035
return bool(resp)
3136
}
3237

3338
func PrivateKeyGenerate() *[32]byte {
34-
resp := C.private_key_generate()
39+
resp := (*ByteArray32)(C.private_key_generate())
3540
defer resp.destroy()
3641
return resp.copyAsArray()
3742
}
3843

3944
func PrivateKeyGenerateWithSeed(rawSeed *ByteArray32) *[32]byte {
40-
resp := C.private_key_generate_with_seed(rawSeed)
45+
resp := (*ByteArray32)(C.private_key_generate_with_seed((*C.uint8_32_array_t)(rawSeed)))
4146
defer resp.destroy()
4247
return resp.copyAsArray()
4348
}
4449

4550
func PrivateKeySign(rawPrivateKey SliceRefUint8, message SliceRefUint8) *[96]byte {
46-
resp := C.private_key_sign(rawPrivateKey, message)
51+
resp := (*ByteArray96)(C.private_key_sign((C.slice_ref_uint8_t)(rawPrivateKey),
52+
(C.slice_ref_uint8_t)(message)))
4753
defer resp.destroy()
4854
return resp.copyAsArray()
4955
}
5056

5157
func PrivateKeyPublicKey(rawPrivateKey SliceRefUint8) *[48]byte {
52-
resp := C.private_key_public_key(rawPrivateKey)
58+
resp := (*ByteArray48)(C.private_key_public_key((C.slice_ref_uint8_t)(rawPrivateKey)))
5359
defer resp.destroy()
5460
return resp.copyAsArray()
5561
}
5662

5763
func CreateZeroSignature() *[96]byte {
58-
resp := C.create_zero_signature()
64+
resp := (*ByteArray96)(C.create_zero_signature())
5965
defer resp.destroy()
6066
return resp.copyAsArray()
6167
}

cgo/fvm.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ package cgo
99
import "C"
1010

1111
func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, tracing bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
12-
resp := C.create_fvm_machine(
13-
fvmVersion,
12+
resp := (*resultFvmMachine)(C.create_fvm_machine(
13+
(C.FvmRegisteredVersion_t)(fvmVersion),
1414
C.uint64_t(chainEpoch),
1515
C.uint64_t(chainTimestamp),
1616
C.uint64_t(chainId),
@@ -19,13 +19,13 @@ func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestam
1919
C.uint64_t(baseCircSupplyHi),
2020
C.uint64_t(baseCircSupplyLo),
2121
C.uint32_t(networkVersion),
22-
stateRoot,
22+
(C.slice_ref_uint8_t)(stateRoot),
2323
C.bool(tracing),
2424
C.uint64_t(blockstoreId),
2525
C.uint64_t(externsId),
26-
)
26+
))
2727
// take out the pointer from the result to ensure it doesn't get freed
28-
executor := resp.value
28+
executor := (*FvmMachine)(resp.value)
2929
resp.value = nil
3030
defer resp.destroy()
3131

@@ -37,8 +37,8 @@ func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestam
3737
}
3838

3939
func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, actorRedirect SliceRefUint8, tracing bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
40-
resp := C.create_fvm_debug_machine(
41-
fvmVersion,
40+
resp := (*resultFvmMachine)(C.create_fvm_debug_machine(
41+
(C.FvmRegisteredVersion_t)(fvmVersion),
4242
C.uint64_t(chainEpoch),
4343
C.uint64_t(chainTimestamp),
4444
C.uint64_t(chainId),
@@ -47,14 +47,14 @@ func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTim
4747
C.uint64_t(baseCircSupplyHi),
4848
C.uint64_t(baseCircSupplyLo),
4949
C.uint32_t(networkVersion),
50-
stateRoot,
51-
actorRedirect,
50+
(C.slice_ref_uint8_t)(stateRoot),
51+
(C.slice_ref_uint8_t)(actorRedirect),
5252
C.bool(tracing),
5353
C.uint64_t(blockstoreId),
5454
C.uint64_t(externsId),
55-
)
55+
))
5656
// take out the pointer from the result to ensure it doesn't get freed
57-
executor := resp.value
57+
executor := (*FvmMachine)(resp.value)
5858
resp.value = nil
5959
defer resp.destroy()
6060

@@ -66,27 +66,27 @@ func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTim
6666
}
6767

6868
func FvmMachineExecuteMessage(executor *FvmMachine, message SliceRefUint8, chainLen, applyKind uint64) (FvmMachineExecuteResponseGo, error) {
69-
resp := C.fvm_machine_execute_message(
70-
executor,
71-
message,
69+
resp := (*resultFvmMachineExecuteResponse)(C.fvm_machine_execute_message(
70+
(*C.InnerFvmMachine_t)(executor),
71+
(C.slice_ref_uint8_t)(message),
7272
C.uint64_t(chainLen),
7373
C.uint64_t(applyKind),
74-
)
74+
))
7575
defer resp.destroy()
7676

7777
if err := CheckErr(resp); err != nil {
7878
return FvmMachineExecuteResponseGo{}, err
7979
}
8080

81-
return resp.value.copy(), nil
81+
return (FvmMachineExecuteResponse)(resp.value).copy(), nil
8282
}
8383

8484
func FvmMachineFlush(executor *FvmMachine) ([]byte, error) {
85-
resp := C.fvm_machine_flush(executor)
85+
resp := (*resultSliceBoxedUint8)(C.fvm_machine_flush((*C.InnerFvmMachine_t)(executor)))
8686
defer resp.destroy()
8787

8888
if err := CheckErr(resp); err != nil {
8989
return nil, err
9090
}
91-
return resp.value.copy(), nil
91+
return (SliceBoxedUint8)(resp.value).copy(), nil
9292
}

0 commit comments

Comments
 (0)