From 63c5d77b5da7554b07990db56dba6e612f11ed87 Mon Sep 17 00:00:00 2001 From: Jamie Holdstock Date: Thu, 15 Feb 2024 18:20:28 +0800 Subject: [PATCH] database: Use bytes.Clone instead of manual copy. bytes.Clone was introduced in go 1.20 and removes the need to manually copy byte slices. --- database/database.go | 9 ++++----- go.mod | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/database/database.go b/database/database.go index e9f7c98b..07407b89 100644 --- a/database/database.go +++ b/database/database.go @@ -1,10 +1,11 @@ -// Copyright (c) 2020-2023 The Decred developers +// Copyright (c) 2020-2024 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. package database import ( + "bytes" "crypto/ed25519" "crypto/rand" "fmt" @@ -285,8 +286,7 @@ func (vdb *VspDatabase) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error) // Byte slices returned from Bolt are only valid during a transaction. // Need to make a copy. - seed = make([]byte, len(s)) - copy(seed, s) + seed = bytes.Clone(s) if seed == nil { // should not happen @@ -341,8 +341,7 @@ func (vdb *VspDatabase) CookieSecret() ([]byte, error) { // Byte slices returned from Bolt are only valid during a transaction. // Need to make a copy. - cookieSecret = make([]byte, len(cs)) - copy(cookieSecret, cs) + cookieSecret = bytes.Clone(cs) return nil }) diff --git a/go.mod b/go.mod index 1d75c946..81ca945c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/decred/vspd -go 1.19 +go 1.20 require ( decred.org/dcrwallet/v3 v3.1.0