Skip to content

Commit 0521dbe

Browse files
changing default algo version and updating docs
1 parent 8a4cf9b commit 0521dbe

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

docs/en/sql-reference/functions/encoding-functions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -975,14 +975,14 @@ Encodes a binary data string, along with a human-readable part (HRP), using the
975975
**Syntax**
976976

977977
```sql
978-
Bech32Encode(hrp, data, witver(optional))
978+
Bech32Encode(hrp, data[, witver])
979979
```
980980

981981
**Parameters**
982982

983983
- `hrp` — String of 1 - 83 lowercase characters specifying the "human-readable part" of the code. Usually 'bc' or 'tb'. [String](../data-types/string.md), [FixedString](../data-types/fixedstring.md).
984984
- `data` — String of binary data to encode. [String](../data-types/string.md), [FixedString](../data-types/fixedstring.md).
985-
- `witver` (optional, default = 0): An [unsigned integer](../../sql-reference/data-types/int-uint.md) specifying the version of the algorithm to run. 0 for Bech32 and 1 or greater for Bech32m.
985+
- `witver` (optional, default = 1): An [unsigned integer](../../sql-reference/data-types/int-uint.md) specifying the version of the algorithm to run. 0 for Bech32 and 1 or greater for Bech32m.
986986

987987
:::note
988988
When using the [FixedString](../data-types/fixedstring.md) data type, if a value does not fully fill the row it is padded with null characters. While the `Bech32Encode` function will handle this automatically for the hrp argument, for the data argument the values must not be padded. For this reason it is not recommended to use the [FixedString](../data-types/fixedstring.md) data type for your data values unless you are certain that they are all the same length and ensure that your [FixedString](../data-types/fixedstring.md) column is set to that length as well.
@@ -996,7 +996,7 @@ Type: [String](../data-types/string.md).
996996

997997
**Example**
998998

999-
When no witness version is supplied, the default is 0, the original Bech32 algorithm.
999+
When no witness version is supplied, the default is 1, the updated Bech32m algorithm.
10001000

10011001
Query:
10021002

@@ -1006,22 +1006,22 @@ SELECT bech32Encode('bc', unhex('751e76e8199196d454941c45d1b3a323f1433bd6'));
10061006
Result:
10071007

10081008
```response
1009-
bc1w508d6qejxtdg4y5r3zarvary0c5xw7kj7gz7z
1009+
bc1w508d6qejxtdg4y5r3zarvary0c5xw7k8zcwmq
10101010
```
10111011

10121012
**Example**
10131013

1014-
A witness version of 1 will result in a different address string.
1014+
A witness version of 0 will result in a different address string.
10151015

10161016
Query:
10171017

10181018
```sql
1019-
SELECT bech32Encode('bc', unhex('751e76e8199196d454941c45d1b3a323f1433bd6'), 1);
1019+
SELECT bech32Encode('bc', unhex('751e76e8199196d454941c45d1b3a323f1433bd6'), 0);
10201020
```
10211021
Result:
10221022

10231023
```response
1024-
bc1w508d6qejxtdg4y5r3zarvary0c5xw7k8zcwmq
1024+
bc1w508d6qejxtdg4y5r3zarvary0c5xw7kj7gz7z
10251025
```
10261026

10271027
**Example**

src/Functions/FunctionsBech32Representation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class EncodeToBech32Representation : public IFunction
100100
public:
101101
static constexpr auto name = "bech32Encode";
102102

103-
// corresponds to the bech32 algo, not the newer bech32m. It seems that the original is the most widely used.
104-
static constexpr int default_witver = 0;
103+
// Default to the new and improved Bech32m algorithm
104+
static constexpr int default_witver = 1;
105105

106106
static FunctionPtr create(ContextPtr) { return std::make_shared<EncodeToBech32Representation>(); }
107107

0 commit comments

Comments
 (0)