@@ -5,25 +5,24 @@ import (
5
5
"github.com/aptos-labs/aptos-go-sdk/bcs"
6
6
"github.com/aptos-labs/aptos-go-sdk/crypto"
7
7
"golang.org/x/crypto/sha3"
8
+ "sync"
8
9
)
9
10
10
11
//region RawTransaction
11
12
12
13
var rawTransactionPrehash []byte
14
+ var rawTransactionWithPrehashOnce sync.Once
13
15
14
16
const rawTransactionPrehashStr = "APTOS::RawTransaction"
15
17
16
18
// RawTransactionPrehash Return the sha3-256 prehash for RawTransaction
17
19
// Do not write to the []byte returned
18
20
func RawTransactionPrehash () []byte {
19
21
// Cache the prehash
20
- if rawTransactionPrehash == nil {
22
+ rawTransactionWithPrehashOnce . Do ( func () {
21
23
b32 := sha3 .Sum256 ([]byte (rawTransactionPrehashStr ))
22
- out := make ([]byte , len (b32 ))
23
- copy (out , b32 [:])
24
- rawTransactionPrehash = out
25
- return out
26
- }
24
+ rawTransactionPrehash = b32 [:]
25
+ })
27
26
return rawTransactionPrehash
28
27
}
29
28
@@ -130,21 +129,20 @@ func (txn *RawTransaction) Sign(signer crypto.Signer) (authenticator *crypto.Acc
130
129
//region RawTransactionWithData
131
130
132
131
var rawTransactionWithDataPrehash []byte
132
+ var rawTransactionWithDataPrehashOnce sync.Once
133
133
134
134
const rawTransactionWithDataPrehashStr = "APTOS::RawTransactionWithData"
135
135
136
136
// RawTransactionWithDataPrehash Return the sha3-256 prehash for RawTransactionWithData
137
137
// Do not write to the []byte returned
138
138
func RawTransactionWithDataPrehash () []byte {
139
139
// Cache the prehash
140
- if rawTransactionWithDataPrehash == nil {
140
+ rawTransactionWithDataPrehashOnce . Do ( func () {
141
141
b32 := sha3 .Sum256 ([]byte (rawTransactionWithDataPrehashStr ))
142
- out := make ([]byte , len (b32 ))
143
- copy (out , b32 [:])
144
- rawTransactionPrehash = out
145
- return out
146
- }
147
- return rawTransactionPrehash
142
+ rawTransactionWithDataPrehash = b32 [:]
143
+ })
144
+ return rawTransactionWithDataPrehash
145
+
148
146
}
149
147
150
148
type RawTransactionWithDataVariant uint32
0 commit comments