From 0cd8ad2ee83a126b2281da0189f3a7ef5161e1c6 Mon Sep 17 00:00:00 2001 From: Jesse <35264598+JesseAtSZ@users.noreply.github.com> Date: Mon, 7 Jul 2025 23:54:52 +0800 Subject: [PATCH 1/3] update library --- 17_Library/readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/17_Library/readme.md b/17_Library/readme.md index 84a3515bc..04fd1cba4 100644 --- a/17_Library/readme.md +++ b/17_Library/readme.md @@ -34,7 +34,7 @@ tags: 3. 不能接收以太币 4. 不可以被销毁 -需要注意的是,库合约中的函数可见性如果被设置为`public`或者`external`,则在调用函数时会触发一次`delegatecall`。而如果被设置为`internal`,则不会引起。对于设置为`private`可见性的函数来说,其仅能在库合约中可见,在其他合约中不可用。 +需要注意的是,库合约中的函数可见性如果被设置为`public`或者`external`,则在调用这个函数时会触发一次`delegatecall`,此时会在调用合约的上下文中执行库合约的代码。而如果被设置为`internal`,则不会触发。对于设置为`private`可见性的函数来说,其仅能在库合约中可见,在其他合约中不可见。 ## Strings库合约 @@ -111,7 +111,7 @@ library Strings { 1. 利用using for指令 - 指令`using A for B;`可用于附加库合约(从库 A)到任何类型(B)。添加完指令后,库`A`中的函数会自动添加为`B`类型变量的成员,可以直接调用。注意:在调用的时候,这个变量会被当作第一个参数传递给函数: + 通过`using A for B;`指令,库合约 A 中的函数可被附加到类型 B 的变量上,​​实现直接调用​​。调用时,变量会自动作为函数的第一个参数传入,无需显式传递: ```solidity // 利用using for指令 @@ -122,7 +122,7 @@ library Strings { } ``` -2. 通过库合约名称调用函数 +3. 通过库合约名称调用函数 ```solidity // 直接通过库合约名调用 @@ -137,7 +137,7 @@ library Strings { ## 总结 -这一讲,我们用`ERC721`的引用的库合约`Strings`为例介绍`Solidity`中的库合约(`Library`)。99%的开发者都不需要自己去写库合约,会用大神写的就可以了。我们只需要知道什么情况该用什么库合约。常用的有: +这一讲,我们以`ERC721`的引用的库合约`Strings`为例介绍`Solidity`中的库合约(`Library`)。99%的开发者都不需要自己去写库合约,会用大神写的就可以了。我们只需要知道什么情况该用什么库合约。常用的有: 1. [Strings](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/4a9cc8b4918ef3736229a5cc5a310bdc17bf759f/contracts/utils/Strings.sol):将`uint256`转换为`String` 2. [Address](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/4a9cc8b4918ef3736229a5cc5a310bdc17bf759f/contracts/utils/Address.sol):判断某个地址是否为合约地址 From c0dd258248f9ea94272ad6b4e6cc4ddc11f47d9b Mon Sep 17 00:00:00 2001 From: Jesse <35264598+JesseAtSZ@users.noreply.github.com> Date: Tue, 8 Jul 2025 00:00:35 +0800 Subject: [PATCH 2/3] update library --- 17_Library/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/17_Library/readme.md b/17_Library/readme.md index 04fd1cba4..3fb794aa8 100644 --- a/17_Library/readme.md +++ b/17_Library/readme.md @@ -122,7 +122,7 @@ library Strings { } ``` -3. 通过库合约名称调用函数 +2. 通过库合约名称调用函数 ```solidity // 直接通过库合约名调用 From 78def15c05fd98c022fd36786e7154061225572a Mon Sep 17 00:00:00 2001 From: Jesse <35264598+JesseAtSZ@users.noreply.github.com> Date: Tue, 8 Jul 2025 18:25:55 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=BC=BA=E8=B0=83using=20A=20for=20B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 17_Library/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/17_Library/readme.md b/17_Library/readme.md index 3fb794aa8..909ab44f0 100644 --- a/17_Library/readme.md +++ b/17_Library/readme.md @@ -111,7 +111,7 @@ library Strings { 1. 利用using for指令 - 通过`using A for B;`指令,库合约 A 中的函数可被附加到类型 B 的变量上,​​实现直接调用​​。调用时,变量会自动作为函数的第一个参数传入,无需显式传递: + 通过`using A for B;`指令,库合约 A 中的函数可被附加到类型 B 的变量上,​​实现直接调用​​。注意:调用时,该变量会自动作为函数的第一个参数传入,无需显式传递: ```solidity // 利用using for指令