Skip to content

Commit

Permalink
Release 2.3.5 (#419)
Browse files Browse the repository at this point in the history
* feat: add command support meta data to blockchain (#410)

* fix: close the client after finish (#411)

* feat: add command support meta data to blockchain

* fix: close the client after finish

* feat: support choose one of the fastest multi rpc (#412)

* feat: decrypt support api download

* feat: decrypt command should be compatible with no hex private key

* feat: update contract address and btfs version

* fix: add timeout and view blockNumber as the sucessful dial

* fix: backend

* feat: update file meta contract address

* feat: update abi

* feat: update dashboard cid

* feat: update discord link

* feat: update docs link
  • Loading branch information
Shawn-Huang-Tron committed Mar 28, 2024
1 parent a5500e3 commit 9fdd194
Show file tree
Hide file tree
Showing 8 changed files with 1,594 additions and 58 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ BitTorrent File System (BTFS) is a next-generation file sharing protocol in the

These are exactly what BTFS aims to clear up. Besides, underpinned by BTTC, BTFS enables cross-chain connectivity and multi-channel payments, making itself a more convenient choice. The intgration of BTFS, BitTorrent, and the BTTC network will boost DApp developers' efficiency in serving a wider market.

* The [documentation](https://docs.btfs.io/v2.0) walks developers through BTFS 2.0 setup, usage, and API references.
* Please join the BTFS community at [discord](https://discord.gg/PQWfzWS).
* The [documentation](https://docs.btfs.io/) walks developers through BTFS 2.0 setup, usage, and API references.
* Please join the BTFS community at [discord](https://discord.com/invite/tJ4fz6C6rw).

## BTFS 2.0 Architecture Diagram

Expand Down Expand Up @@ -43,7 +43,7 @@ In order to ensure the normal use of btfs 2.0 testnet, you need to apply for BTT

## Install BTFS

The download and install instructions for BTFS are over at: https://docs.btfs.io/v2.0/docs/install-run-btfs20-node.
The download and install instructions for BTFS are over at: https://docs.btfs.io/docs/install-run-btfs20-node.

### System Requirements

Expand Down Expand Up @@ -334,7 +334,7 @@ If you make changes to the protocol buffers, you will need to install the [proto

BTFS Gateway is a free service that allows you to retrieve files from the BTFS network in your browser directly.

[How to use BTFS Gateway](https://docs.btfs.io/v2.0/docs/btfs-gateway-user-guide-1)
[How to use BTFS Gateway](https://docs.btfs.io/docs/btfs-gateway-user-guide-1)

## License

Expand Down
1,441 changes: 1,441 additions & 0 deletions chain/abi/FileMeta.go

Large diffs are not rendered by default.

47 changes: 34 additions & 13 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,43 @@ func InitChain(
peerid string,
chainconfig *config.ChainConfig,
) (*ChainInfo, error) {

StateStore = stateStore
var backend *ethclient.Client
var err error
if len(chainconfig.MultiEndpoint) > 0 {
var backendChan chan *ethclient.Client = make(chan *ethclient.Client, len(chainconfig.MultiEndpoint))
for _, endpoint := range chainconfig.MultiEndpoint {
go func(e string) {
b, err := ethclient.Dial(e)
if err != nil {
return
}
_, err = b.BlockNumber(context.Background())
if err != nil {
return
}
backendChan <- b
}(endpoint)
}
select {
case backend = <-backendChan:
case <-time.After(time.Second * 60):
return nil, errors.New("could not connect all rpc configuration after 1 min, please try again or check your network")
}
} else {
backend, err = ethclient.Dial(chainconfig.Endpoint)
if err != nil {
return nil, fmt.Errorf("dial eth client: %w", err)
}
_, err = backend.BlockNumber(context.Background())
if err != nil {
errMsg := "Could not connect to blockchain rpc, please check your network connection"
if err == io.EOF {
return nil, errors.New(errMsg)

backend, err := ethclient.Dial(chainconfig.Endpoint)
if err != nil {
return nil, fmt.Errorf("dial eth client: %w", err)
}

_, err = backend.BlockNumber(context.Background())
if err != nil {
errMsg := "Could not connect to blockchain rpc, please check your network connection"
if err == io.EOF {
return nil, errors.New(errMsg)

}
return nil, fmt.Errorf("%s.%w", errMsg, err)
}
return nil, fmt.Errorf("%s.%w", errMsg, err)
}

overlayEthAddress, err := signer.EthereumAddress()
Expand Down
25 changes: 20 additions & 5 deletions chain/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"errors"

cfg "github.com/bittorrent/go-btfs-config"
"github.com/ethereum/go-ethereum/common"
)
Expand Down Expand Up @@ -36,6 +37,7 @@ var (
//bttcTestVaultLogicAddress = common.HexToAddress("0x73bcbE03999913dB7229FD5dC485cf23247c58B5") // https://testnet.bttcscan.com/address/0x67F0366c4c0c83F55D4759D301BEe051EF01E350
bttcTestMutiVaultLogicAddress = common.HexToAddress("0x67F0366c4c0c83F55D4759D301BEe051EF01E350") // https://testnet.bttcscan.com/address/0x67F0366c4c0c83F55D4759D301BEe051EF01E350
bttcTestStatusAddress = common.HexToAddress("0x38d1fF2C2e9744273E4531FA4608eB6432c1F26A")
bttcTestFileMetaAddress = common.HexToAddress("0xB192bb91c143C196EF3c659923Ef34026B170997")

bttcFactoryAddressV1 = common.HexToAddress("0x9AF4bEc1A30BeC47756Ecef4cf43B91592121bC9")
bttcFactoryAddress = common.HexToAddress("0x763d7858287B9a33F4bE5bb3df0241dACc59BCc7") // https://bttcscan.com/address/0x763d7858287B9a33F4bE5bb3df0241dACc59BCc7
Expand All @@ -46,6 +48,7 @@ var (
//bttcVaultLogicAddress = common.HexToAddress("0x11a91B7270ea000768F7A2C543547e832b5cb031") // https://bttcscan.com/address/0x11a91B7270ea000768F7A2C543547e832b5cb031
bttcMutiVaultLogicAddress = common.HexToAddress("0x5c67bED46336A59252b73a0fA22B9de1cffb172e")
bttcStatusAddress = common.HexToAddress("0x6DBAd4Bd16C15AE6dDEaA640626e5A3E151F02fC")
bttcFileMetaAddress = common.HexToAddress("0xe74117DC4A3457Eb32436F8F3De10701a3C4F6d7")

// deploy gas
ethDeploymentGas = "10"
Expand All @@ -58,11 +61,17 @@ var (
testDeploymentGas = ""

//endpoint
ethEndpoint = ""
tronEndpoint = ""
bttcEndpoint = "https://rpc.bittorrentchain.io/"
bttcTestEndpoint = "https://pre-rpc.bt.io/"
testEndpoint = "http://18.144.29.246:8110"
ethEndpoint = ""
tronEndpoint = ""
bttcEndpoint = "https://rpc.bittorrentchain.io/"
bttcTestEndpoint = "https://pre-rpc.bt.io/"
testEndpoint = "http://18.144.29.246:8110"
bttcMultiEndpoint = []string{
"https://rpc.bittorrentchain.io/",
"https://rpc.bt.io/",
"https://bttc.trongrid.io/",
}
bttcTestMultiEndpoint = []string{"https://pre-rpc.bt.io/"}

DefaultChain = bttcChainID
)
Expand All @@ -84,6 +93,8 @@ type ChainConfig struct {
DeploymentGas string
Endpoint string
StatusAddress common.Address
FileMetaAddress common.Address
MultiEndpoint []string
}

func GetChainConfig(chainID int64) (*ChainConfig, bool) {
Expand Down Expand Up @@ -114,6 +125,8 @@ func GetChainConfig(chainID int64) (*ChainConfig, bool) {
cfg.Endpoint = bttcEndpoint
cfg.BatchAddress = bttcBatchAddress
cfg.StatusAddress = bttcStatusAddress
cfg.FileMetaAddress = bttcFileMetaAddress
cfg.MultiEndpoint = bttcMultiEndpoint
return &cfg, true
case bttcTestChainID:
cfg.StartBlock = bttcStartBlock
Expand All @@ -124,6 +137,8 @@ func GetChainConfig(chainID int64) (*ChainConfig, bool) {
cfg.BatchAddress = bttcTestBatchAddress
cfg.VaultLogicAddress = bttcTestMutiVaultLogicAddress
cfg.StatusAddress = bttcTestStatusAddress
cfg.FileMetaAddress = bttcTestFileMetaAddress
cfg.MultiEndpoint = bttcTestMultiEndpoint
return &cfg, true
case testChainID:
cfg.StartBlock = ethStartBlock
Expand Down
113 changes: 91 additions & 22 deletions core/commands/add.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package commands

import (
"encoding/base64"
"errors"
"fmt"
"io"
"math/big"
"os"
"path"
"strings"

"github.com/bittorrent/go-btfs/chain/abi"
chainconfig "github.com/bittorrent/go-btfs/chain/config"
oldcmds "github.com/bittorrent/go-btfs/commands"
"github.com/bittorrent/go-btfs/core/commands/cmdenv"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
ethCrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"

cmds "github.com/bittorrent/go-btfs-cmds"
files "github.com/bittorrent/go-btfs-files"
coreiface "github.com/bittorrent/interface-go-btfs-core"
"github.com/bittorrent/interface-go-btfs-core/options"
coreifacePath "github.com/bittorrent/interface-go-btfs-core/path"
mh "github.com/multiformats/go-multihash"
pb "gopkg.in/cheggaaa/pb.v1"
)
Expand All @@ -29,26 +40,27 @@ type AddEvent struct {
}

const (
quietOptionName = "quiet"
quieterOptionName = "quieter"
silentOptionName = "silent"
progressOptionName = "progress"
trickleOptionName = "trickle"
wrapOptionName = "wrap-with-directory"
onlyHashOptionName = "only-hash"
chunkerOptionName = "chunker"
pinOptionName = "pin"
rawLeavesOptionName = "raw-leaves"
noCopyOptionName = "nocopy"
fstoreCacheOptionName = "fscache"
hashOptionName = "hash"
inlineOptionName = "inline"
inlineLimitOptionName = "inline-limit"
tokenMetaOptionName = "meta"
encryptName = "encrypt"
pubkeyName = "public-key"
peerIdName = "peer-id"
pinDurationCountOptionName = "pin-duration-count"
quietOptionName = "quiet"
quieterOptionName = "quieter"
silentOptionName = "silent"
progressOptionName = "progress"
trickleOptionName = "trickle"
wrapOptionName = "wrap-with-directory"
onlyHashOptionName = "only-hash"
chunkerOptionName = "chunker"
pinOptionName = "pin"
rawLeavesOptionName = "raw-leaves"
noCopyOptionName = "nocopy"
fstoreCacheOptionName = "fscache"
hashOptionName = "hash"
inlineOptionName = "inline"
inlineLimitOptionName = "inline-limit"
tokenMetaOptionName = "meta"
encryptName = "encrypt"
pubkeyName = "public-key"
peerIdName = "peer-id"
pinDurationCountOptionName = "pin-duration-count"
uploadToBlockchainOptionName = "to-blockchain"
)

const adderOutChanSize = 8
Expand Down Expand Up @@ -155,6 +167,7 @@ only-hash, and progress/status related flags) will change the final hash.
cmds.StringOption(pubkeyName, "The public key to encrypt the file."),
cmds.StringOption(peerIdName, "The peer id to encrypt the file."),
cmds.IntOption(pinDurationCountOptionName, "d", "Duration for which the object is pinned in days.").WithDefault(0),
cmds.BoolOption(uploadToBlockchainOptionName, "add file meta to blockchain").WithDefault(false),
},
PreRun: func(req *cmds.Request, env cmds.Environment) error {
quiet, _ := req.Options[quietOptionName].(bool)
Expand Down Expand Up @@ -200,6 +213,7 @@ only-hash, and progress/status related flags) will change the final hash.
pubkey, _ := req.Options[pubkeyName].(string)
peerId, _ := req.Options[peerIdName].(string)
pinDuration, _ := req.Options[pinDurationCountOptionName].(int)
uploadToBlockchain, _ := req.Options[uploadToBlockchainOptionName].(bool)

hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)]
if !ok {
Expand Down Expand Up @@ -265,11 +279,11 @@ only-hash, and progress/status related flags) will change the final hash.
errCh := make(chan error, 1)
events := make(chan interface{}, adderOutChanSize)
opts[len(opts)-1] = options.Unixfs.Events(events)

var pr coreifacePath.Resolved
go func() {
var err error
defer close(events)
_, err = api.Unixfs().Add(req.Context, addit.Node(), opts...)
pr, err = api.Unixfs().Add(req.Context, addit.Node(), opts...)
errCh <- err
}()

Expand Down Expand Up @@ -304,6 +318,61 @@ only-hash, and progress/status related flags) will change the final hash.
return err
}
added++
if uploadToBlockchain {
cctx := env.(*oldcmds.Context)
cfg, err := cctx.GetConfig()
if err != nil {
return err
}
fname := addit.Name()
size, _ := addit.Node().Size()
cli, err := ethclient.Dial(cfg.ChainInfo.Endpoint)
if err != nil {
return err
}
defer cli.Close()
currChainCfg, ok := chainconfig.GetChainConfig(cfg.ChainInfo.ChainId)
if !ok {
return fmt.Errorf("chain %d is not supported yet", cfg.ChainInfo.ChainId)
}
contractAddress := currChainCfg.FileMetaAddress
contr, err := abi.NewFileMeta(contractAddress, cli)
if err != nil {
return err
}
pkbytesOri, err := base64.StdEncoding.DecodeString(cfg.Identity.PrivKey)
if err != nil {
return err
}
privateKey, err := ethCrypto.ToECDSA(pkbytesOri[4:])
if err != nil {
return err
}
fromAddress := crypto.PubkeyToAddress(privateKey.PublicKey)
nonce, err := cli.PendingNonceAt(req.Context, fromAddress)
if err != nil {
return err
}
auth, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(cfg.ChainInfo.ChainId))
if err != nil {
return err
}
auth.Nonce = big.NewInt(int64(nonce))
auth.Value = big.NewInt(0)
data := abi.FileMetaFileMetaData{
OwnerPeerId: cfg.Identity.PeerID,
From: common.HexToAddress(cfg.Identity.BttcAddr),
FileName: fname,
FileExt: path.Ext(fname),
IsDir: dir,
FileSize: big.NewInt(size),
}
tx, err := contr.AddFileMeta(auth, pr.Cid().String(), data)
if err != nil {
return err
}
fmt.Println("Write into file meta contract successfully! Transaction hash is: ", tx.Hash().Hex())
}
}

if addit.Err() != nil {
Expand Down
13 changes: 1 addition & 12 deletions core/commands/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/base64"
"errors"
"io"
"os"

shell "github.com/bittorrent/go-btfs-api"
cmds "github.com/bittorrent/go-btfs-cmds"
Expand Down Expand Up @@ -143,17 +142,7 @@ var decryptCmd = &cmds.Command{
if err != nil {
return errors.New("decryption is failed, maybe the content of encryption is not encrypted by your public key")
}
fileName := "./decrypt-file-of-" + cid
f, err := os.Create(fileName)
if err != nil {
return err
}
defer f.Close()
_, err = f.Write(dedata)
if err != nil {
return err
}
return re.Emit("decrypted file name is: " + fileName)
return re.Emit(bytes.NewReader(dedata))
},
}

Expand Down
3 changes: 2 additions & 1 deletion core/corehttp/webui.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package corehttp

const WebUIPath = "/btfs/QmPFT7PscyJ1FZ4FeFPFgikszBugQSBFNycPpy5zpK2pZe" // v2.3.3
const WebUIPath = "/btfs/QmSTcj1pWk972bdtStQtJeu3yCYo1SDShrbEHaEybciTLR" // v2.3.5

// this is a list of all past webUI paths.
var WebUIPaths = []string{
WebUIPath,
"/btfs/QmPFT7PscyJ1FZ4FeFPFgikszBugQSBFNycPpy5zpK2pZe", // v2.3.3
"/btfs/QmUKCyDc4h9KN93AdZ7ZVqgPProsKs8NAbVJkK3ux9788d", // v2.3.2
"/btfs/QmRdt8SzRBz5px7KfU4hFveJSKzBMFqv73YE4xXJBsVdDJ", // v2.3.1
"/btfs/QmbNHqcL9PEhFdT5mXjNnkaAE8SEFkjr2jD7we2ckTL4Li", // v2.3.0
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package btfs
var CurrentCommit string

// CurrentVersionNumber is the current application's version literal
const CurrentVersionNumber = "2.3.4"
const CurrentVersionNumber = "2.3.5"

const ApiVersion = "/go-btfs/" + CurrentVersionNumber + "/"

Expand Down

0 comments on commit 9fdd194

Please sign in to comment.