以太坊ETH-智能合约开发-solidity源码分析-truffle进阶

2024-05-07 13:32

本文主要是介绍以太坊ETH-智能合约开发-solidity源码分析-truffle进阶,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

0. 背景

上一篇文章我们从合约编写、编译、部署、交互等几个方面介绍了truffle的大致用法。
本篇主要继续深入地介绍truffle的高级用法 + 合约源码分析

1. 将合约部署到测试网Ropsten

1.1 注册infura获取API-KEY

infura是基于ETH的chain公共API服务,为开发者提供链上数据查询、交易广播等功能。

1.2 准备助记词

可从Web钱包MetaMask 上进行创建并导出助记词
一个助记词可以对应多个网络环境的地址,请勿向助记词对应的地址转入主网的ETH,否则有一定的安全风险

1.3 安装 truffle-hdwallet-provider

由于需要将合约部署到测试网Ropsten,此过程需要部署者私钥进行签名再将数据进行广播,truffle-hdwallet-providertruffle上提供交易离线签名的模块
:必须在truffle框架的代码目录下安装,否则不生效

 ✘ wujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi  npm install truffle-hdwallet-provider
npm WARN deprecated truffle-hdwallet-provider@1.0.17: WARNING: This package has been renamed to @truffle/hdwallet-provider.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142> websocket@1.0.29 install /Users/wujinquan/workspace/eth/truffle/defi/node_modules/web3-providers-ws/node_modules/websocket
> (node-gyp rebuild 2> builderror.log) || (exit 0)CXX(target) Release/obj.target/bufferutil/src/bufferutil.o> websocket@1.0.31 install /Users/wujinquan/workspace/eth/truffle/defi/node_modules/websocket
> (node-gyp rebuild 2> builderror.log) || (exit 0)CXX(target) Release/obj.target/bufferutil/src/bufferutil.oSOLINK_MODULE(target) Release/bufferutil.nodeCXX(target) Release/obj.target/validation/src/validation.oSOLINK_MODULE(target) Release/validation.node
npm WARN saveError ENOENT: no such file or directory, open '/Users/wujinquan/workspace/eth/truffle/defi/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/wujinquan/workspace/eth/truffle/defi/package.json'
npm WARN defi No description
npm WARN defi No repository field.
npm WARN defi No README data
npm WARN defi No license field.+ truffle-hdwallet-provider@1.0.17
added 326 packages from 212 contributors and audited 20646 packages in 114.122s
found 2 vulnerabilities (1 low, 1 high)run `npm audit fix` to fix them, or `npm audit` for details╭────────────────────────────────────────────────────────────────╮│                                                                ││      New minor version of npm available! 6.13.4 → 6.14.2       ││   Changelog: https://github.com/npm/cli/releases/tag/v6.14.2   ││               Run npm install -g npm to update!                ││                                                                │╰────────────────────────────────────────────────────────────────╯wujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi  ls
build             defi              node_modules      test
contracts         migrations        package-lock.json truffle-config.jswujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi 
1.4 修改truffle配置

主要修改ropsten网络配置,使truffle能顺利与ropsten交互

/*** Use this file to configure your truffle project. It's seeded with some* common settings for different networks and features like migrations,* compilation and testing. Uncomment the ones you need or modify* them to suit your project as necessary.** More information about configuration can be found at:** truffleframework.com/docs/advanced/configuration** To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)* to sign your transactions before they're sent to a remote public node. Infura accounts* are available for free at: infura.io/register.** You'll also need a mnemonic - the twelve word phrase the wallet uses to generate* public/private key pairs. If you're publishing your code to GitHub make sure you load this* phrase from a file you've .gitignored so it doesn't accidentally become public.**/const HDWalletProvider = require("truffle-hdwallet-provider");
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();
const mnemonic = "grant boat distance require trap pair theme together spray blush glory simple"
//0x843ACfB41E5c0F1E0587C5B765d897cCDeA8c4DDmodule.exports = {/*** Networks define how you connect to your ethereum client and let you set the* defaults web3 uses to send transactions. If you don't specify one truffle* will spin up a development blockchain for you on port 9545 when you* run `develop` or `test`. You can ask a truffle command to use a specific* network from the command line, e.g** $ truffle test --network <network-name>*/networks: {// Useful for testing. The `development` name is special - truffle uses it by default// if it's defined here and no other network is specified at the command line.// You should run a client (like ganache-cli, geth or parity) in a separate terminal// tab if you use this network and you must also set the `host`, `port` and `network_id`// options below to some value.//// development: {//  host: "127.0.0.1",     // Localhost (default: none)//  port: 8545,            // Standard Ethereum port (default: none)//  network_id: "*",       // Any network (default: none)// },// Another network with more advanced options...// advanced: {// port: 8777,             // Custom port// network_id: 1342,       // Custom network// gas: 8500000,           // Gas sent with each transaction (default: ~6700000)// gasPrice: 20000000000,  // 20 gwei (in wei) (default: 100 gwei)// from: <address>,        // Account to send txs from (default: accounts[0])// websockets: true        // Enable EventEmitter interface for web3 (default: false)// },// Useful for deploying to a public network.// NB: It's important to wrap the provider as a function.ropsten: {provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/5c93axxx`),//示例无效network_id: 3,       // Ropsten's idgas: 5500000,        // Ropsten has a lower block limit than mainnetconfirmations: 2,    // # of confs to wait between deployments. (default: 0)timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )}// Useful for private networks// private: {// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),// network_id: 2111,   // This network is yours, in the cloud.// production: true    // Treats this network as if it was a public net. (default: false)// }},// Set default mocha options here, use special reporters etc.mocha: {// timeout: 100000},// Configure your compilerscompilers: {solc: {// version: "0.5.1",    // Fetch exact version from solc-bin (default: truffle's version)// docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)// settings: {          // See the solidity docs for advice about optimization and evmVersion//  optimizer: {//    enabled: false,//    runs: 200//  },//  evmVersion: "byzantium"// }}}
}
1.5 部署至Ropsten

执行truffle migrate --network ropsten --reset 即可部署至Ropsten
如需要重新编译所有合约,可执行truffle migrate --network ropsten --reset --compile-all

 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi  truffle migrate --network ropsten --resetCompiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.Starting migrations...
======================
> Network name:    'ropsten'
> Network id:      3
> Block gas limit: 0x7a121d1_initial_migration.js
======================Replacing 'Migrations'----------------------> transaction hash:    0x349ca58d8ed2176265efc58bf232878d930c71436a9b39796062489a638de396> Blocks: 2            Seconds: 92> contract address:    0x619DB4dda0cd2b3fF6351F52828Af5Cc44E6cA55> block number:        7531302> block timestamp:     1584376631> account:             0x843ACfB41E5c0F1E0587C5B765d897cCDeA8c4DD> balance:             0.47030684> gas used:            164175> gas price:           20 gwei> value sent:          0 ETH> total cost:          0.0032835 ETHPausing for 2 confirmations...------------------------------> confirmation number: 1 (block: 7531303)> confirmation number: 3 (block: 7531305)> Saving migration to chain.> Saving artifacts-------------------------------------> Total cost:           0.0032835 ETH2_deploy_contracts.js
=====================Replacing 'DeFi'----------------> transaction hash:    0x4be50b4e7a560080de6587078f937a553f29ac7b04ccd2e6b3802dc75dc8fe61> Blocks: 1            Seconds: 63> contract address:    0xB378420cde84c7A73EecfAeE2fC91ED364F45E9F> block number:        7531309> block timestamp:     1584376852> account:             0x843ACfB41E5c0F1E0587C5B765d897cCDeA8c4DD> balance:             0.4474762> gas used:            1099191> gas price:           20 gwei> value sent:          0 ETH> total cost:          0.02198382 ETHPausing for 2 confirmations...------------------------------> confirmation number: 1 (block: 7531310)> confirmation number: 2 (block: 7531311)> Saving migration to chain.> Saving artifacts-------------------------------------> Total cost:          0.02198382 ETHSummary
=======
> Total deployments:   2
> Final cost:          0.02526732 ETHwujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi 
1.6 从区块浏览器上查看已部署的合约

从log输出可见DeFi合约地址为0xB378420cde84c7A73EecfAeE2fC91ED364F45E9F

2. 合约源码分析

项目源码可见Github仓库,主要分析DeFi.sol,过程以下代码中的详细中英文注释

pragma solidity >=0.4.25 <0.7.0;contract Token{mapping (address => uint256) balances;string  public name;string  public symbol;uint8   public decimals;uint256 public totalSupply;mapping (address => mapping (address => uint256)) allowed;//ERC20 Token Standard: https://eips.ethereum.org/EIPS/eip-20constructor() public { name = "Token";                                         	// Set the name symbol = "TK";                                              // Set the symbol decimals = 18;                                              // Amount of decimals for display purposes
//		totalSupply = 1000000000000000000000;                       // Not set total supply	}//Returns the account balance of another account with address _owner.function balanceOf(address _owner) public view returns (uint256 balance) {return balances[_owner];	}/* Transfers _value amount of tokens to address _to, and MUST fire the Transfer event. The function SHOULD throw if the message caller’s account balance does not have enough tokens to spend.Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.*/function transfer(address _to, uint256 _value) public returns (bool success) {require(_value > 0 );                                      // Check if token's value to be send > 0require(balances[msg.sender] >= _value);                   // Check if the sender has enough tokenrequire(balances[_to] + _value > balances[_to]);           // Check for overflows											balances[msg.sender] -= _value;                            // Subtract token from the senderbalances[_to] += _value;                                   // Add the same amount to the receiver                      emit Transfer(msg.sender, _to, _value); 				   // Notify anyone listening that this transaction happen.return true;      }/* The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies. The function SHOULD throw unless the _from account has deliberately authorized the sender of the message via some mechanism.Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.*/function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {require(balances[_from] >= _value);                 // Check if the sender has enough tokenrequire(balances[_to] + _value >= balances[_to]);   // Check for overflowsrequire(_value <= allowed[_from][msg.sender]);      // Check allowancebalances[_from] -= _value;                          // Subtract from the senderbalances[_to] += _value;                            // Add the same amount to the receiverallowed[_from][msg.sender] -= _value;emit Transfer(_from, _to, _value);return true;}/* Allows _spender to withdraw from your account multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value.NOTE: To prevent attack vectors like the one described here and discussed here, clients SHOULD make sure to create user interfaces in such a way that they set the allowance first to 0 before setting it to another value for the same spender. THOUGH The contract itself shouldn’t enforce it, to allow backwards compatibility with contracts deployed before */function approve(address _spender, uint256 _value) public returns (bool success) {require(balances[msg.sender] >= _value);allowed[msg.sender][_spender] = _value;emit Approval(msg.sender, _spender, _value);return true;}//Returns the amount which _spender is still allowed to withdraw from _owner.function allowance(address _owner, address _spender) public view returns (uint256 remaining) {return allowed[_owner][_spender];}//The event for tranfer and approveevent Transfer(address indexed _from, address indexed _to, uint256 _value);event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}contract DeFi is Token{ //声明owner,暂时没作用address public owner ;//声明 用户-抵押ETH数量 mappingmapping (address => uint) pledgeETHAmount;//声明 抵押/赎回时的eventevent Pledge(address user, uint256 amount);event Redeem(address user, uint256 amount);//构造函数,只在合约被部署的时候执行一次constructor() public {owner = msg.sender ;}//抵押功能function pledge() public payable returns(bool success){//ETH抵押金额必须大于0require(msg.value > 0, "Not enough ETH to pledge.");//抵押操作// 1. 1:1贷出ERC20 TokenToken.balances[msg.sender] += msg.value;// 2. 写入抵押信息map,记录用户抵押ETH的数量:单位weipledgeETHAmount[msg.sender] += msg.value;// 3. 更新Token总量Token.totalSupply += msg.value;//记录抵押事件emit Pledge(msg.sender,msg.value);return true;}//赎回功能function redeem(uint256 value) public returns(bool success){//要求赎回ETH的数量必须 <= Token余额require(value <= Token.balances[msg.sender],"Not enough ETH to redeem.");//赎回操作// 1. 在合约转出ETH到用户地址之前将待发金额清零,更新用户Token余额和Token总量,来防止重入(re-entrancy)攻击Token.balances[msg.sender] -= value;Token.totalSupply -=  value;// 2. 从合约里转ETH到对应用户msg.sender.transfer(value);//记录赎回事件emit Redeem(msg.sender,value);return true;}
}

3. 与合约交互

在项目目录中执行truffle console --network ropsten连接ropsten并进入console模式

3.0 定义常用的抽象合约对象
truffle(ropsten)> let defi = await DeFi.deployed()  //合约对象定义为defi
undefined
truffle(ropsten)> let contractaddr = await defi.address 合约地址定义为contractaddr
undefined
truffle(ropsten)>
3.1 调用合约抵押ETH贷出ERC20代币TK

可见区块浏览器https://ropsten.etherscan.io/tx/0x6dcb3790976b0d3a6f0715739a3c771f192f39b3f1d2995a88f718d6df30c6d9

truffle(ropsten)> defi.pledge.sendTransaction({from:accounts[0],value:101}) //指定sender和抵押ETH数量,回显需要一点时间
{tx: '0x6dcb3790976b0d3a6f0715739a3c771f192f39b3f1d2995a88f718d6df30c6d9',receipt: {blockHash: '0x15b79d45581d83e7f5aaa40a9fac51c13d1824f188869207948c050fc4ded8ae',blockNumber: 7531333,contractAddress: null,cumulativeGasUsed: 85311,from: '0x843acfb41e5c0f1e0587c5b765d897ccdea8c4dd',gasUsed: 85311,logs: [ [Object] ],logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000200000000000000000000000000000000000040000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',status: true,to: '0xb378420cde84c7a73eecfaee2fc91ed364f45e9f',transactionHash: '0x6dcb3790976b0d3a6f0715739a3c771f192f39b3f1d2995a88f718d6df30c6d9',transactionIndex: 0,rawLogs: [ [Object] ]},logs: [{address: '0xB378420cde84c7A73EecfAeE2fC91ED364F45E9F',blockHash: '0x15b79d45581d83e7f5aaa40a9fac51c13d1824f188869207948c050fc4ded8ae',blockNumber: 7531333,logIndex: 0,removed: false,transactionHash: '0x6dcb3790976b0d3a6f0715739a3c771f192f39b3f1d2995a88f718d6df30c6d9',transactionIndex: 0,id: 'log_818726e7',event: 'Pledge',args: [Result]}]
}
truffle(ropsten)>
3.2 查询合约余额和用户的Token余额是否达到预期
truffle(ropsten)> web3.eth.getBalance(contractaddr) //合约的ETH余额
'101'
truffle(ropsten)> defi.balanceOf(accounts[0]) //用户的Token余额
BN {negative: 0,words: [ 101, <1 empty item> ],length: 1,red: null
}
truffle(ropsten)>
3.3 调用合约归还ERC20代币TK,赎回ETH

可见区块浏览器https://ropsten.etherscan.io/tx/0xa720d3da5eda30b9a816e68aaf41ddde0a536c2307734317f6b15243fb9b1829

truffle(ropsten)> defi.redeem.sendTransaction(99,{from:accounts[0]})  //归还99`TK`,1比1 赎回99`wei``ETH`
Error: Invalid JSON RPC response: ""at Object.InvalidResponse (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/web3/node_modules/web3-core-helpers/src/errors.js:42:1)at t.InvalidResponse [as onreadystatechange] (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/web3/node_modules/web3-providers-http/src/index.js:92:1)at t._a [as dispatchEvent] (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:27:61)at t.dispatchEvent [as _setReadyState] (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)at t._setReadyState [as _onHttpRequestError] (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:349:1)at ClientRequest._onHttpRequestError (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:252:47)at ClientRequest.emit (events.js:305:20)at ClientRequest.EventEmitter.emit (domain.js:483:12)at TLSSocket.socketErrorListener (_http_client.js:423:9)at TLSSocket.emit (events.js:305:20)at TLSSocket.EventEmitter.emit (domain.js:483:12)at emitErrorNT (internal/streams/destroy.js:84:8)at processTicksAndRejections (internal/process/task_queues.js:84:21)
{tx: '0xa720d3da5eda30b9a816e68aaf41ddde0a536c2307734317f6b15243fb9b1829',receipt: {blockHash: '0x0a08ef737e0729f31a2bd428eb50273833f669ebfc95b622cdf405c67996ceef',blockNumber: 7531341,contractAddress: null,cumulativeGasUsed: 756933,from: '0x843acfb41e5c0f1e0587c5b765d897ccdea8c4dd',gasUsed: 43116,logs: [ [Object] ],logsBloom: '0x00000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000040000000000000000000000000000000040000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000',status: true,to: '0xb378420cde84c7a73eecfaee2fc91ed364f45e9f',transactionHash: '0xa720d3da5eda30b9a816e68aaf41ddde0a536c2307734317f6b15243fb9b1829',transactionIndex: 1,rawLogs: [ [Object] ]},logs: [{address: '0xB378420cde84c7A73EecfAeE2fC91ED364F45E9F',blockHash: '0x0a08ef737e0729f31a2bd428eb50273833f669ebfc95b622cdf405c67996ceef',blockNumber: 7531341,logIndex: 1,removed: false,transactionHash: '0xa720d3da5eda30b9a816e68aaf41ddde0a536c2307734317f6b15243fb9b1829',transactionIndex: 1,id: 'log_2be7cb64',event: 'Redeem',args: [Result]}]
}
truffle(ropsten)>
3.4 查询赎回后合约余额和用户的Token余额是否达到预期
truffle(ropsten)> web3.eth.getBalance(contractaddr) //合约的ETH余额
'2'
truffle(ropsten)> defi.balanceOf(accounts[0]) //用户的Token余额
BN { negative: 0, words: [ 2, <1 empty item> ], length: 1, red: null }
truffle(ropsten)>

4.其它部署调试工具

对于开发者而言,可使用可视化工具Remix进行合约调试、部署
同一例子,详细参考以太坊ETH-智能合约开发-Remix使用

这篇关于以太坊ETH-智能合约开发-solidity源码分析-truffle进阶的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/967483

相关文章

Spring Security基于数据库的ABAC属性权限模型实战开发教程

《SpringSecurity基于数据库的ABAC属性权限模型实战开发教程》:本文主要介绍SpringSecurity基于数据库的ABAC属性权限模型实战开发教程,本文给大家介绍的非常详细,对大... 目录1. 前言2. 权限决策依据RBACABAC综合对比3. 数据库表结构说明4. 实战开始5. MyBA

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

kotlin中const 和val的区别及使用场景分析

《kotlin中const和val的区别及使用场景分析》在Kotlin中,const和val都是用来声明常量的,但它们的使用场景和功能有所不同,下面给大家介绍kotlin中const和val的区别,... 目录kotlin中const 和val的区别1. val:2. const:二 代码示例1 Java

Go标准库常见错误分析和解决办法

《Go标准库常见错误分析和解决办法》Go语言的标准库为开发者提供了丰富且高效的工具,涵盖了从网络编程到文件操作等各个方面,然而,标准库虽好,使用不当却可能适得其反,正所谓工欲善其事,必先利其器,本文将... 目录1. 使用了错误的time.Duration2. time.After导致的内存泄漏3. jsO

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

Spring事务中@Transactional注解不生效的原因分析与解决

《Spring事务中@Transactional注解不生效的原因分析与解决》在Spring框架中,@Transactional注解是管理数据库事务的核心方式,本文将深入分析事务自调用的底层原理,解释为... 目录1. 引言2. 事务自调用问题重现2.1 示例代码2.2 问题现象3. 为什么事务自调用会失效3

找不到Anaconda prompt终端的原因分析及解决方案

《找不到Anacondaprompt终端的原因分析及解决方案》因为anaconda还没有初始化,在安装anaconda的过程中,有一行是否要添加anaconda到菜单目录中,由于没有勾选,导致没有菜... 目录问题原因问http://www.chinasem.cn题解决安装了 Anaconda 却找不到 An