Skip to content

jhl8109/FabricAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Smart Contract Management System

ํ•˜์ดํผ๋ ˆ์ € ํŒจ๋ธŒ๋ฆญ์—์„œ ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ์— ๋Œ€ํ•œ

์žฌ์‚ฌ์šฉ์„ฑ, ํ™•์žฅ์„ฑ์„ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•œ ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์ž…๋‹ˆ๋‹ค.

ํ•˜์ดํผ๋ ˆ์ € ํŒจ๋ธŒ๋ฆญ์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ฑ, ์ด์šฉ์„ฑ ์ฆ๋Œ€๋ฅผ ๋ชฉํ‘œ๋กœ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๋ชฉ์ฐจ

1. ์ฃผ์š” ๊ธฐ๋Šฅ
2. ์‚ฌ์šฉ ๊ธฐ์ˆ 
3. ์•„ํ‚คํ…์ฒ˜ ๋ฐ ํ๋ฆ„๋„
4. ๊ฐœ๋ฐœ
โ€ƒ4-1. ์ฝ”๋“œ
โ€ƒ4-2. ํ™”๋ฉด
5. ํ‰๊ฐ€
6. ๊ฒฐ๊ณผ

์ฃผ์š” ๊ธฐ๋Šฅ

  • ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ ์—…๋กœ๋“œ
  • ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ ๋Œ€์‹œ๋ณด๋“œ - ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ ๊ฒ€์ƒ‰ / ๋น„๊ต
  • ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ ์ƒ์„ธ ์ •๋ณด - ์„ค์น˜ / ๋‹ค์šด๋กœ๋“œ / ํŠธ๋žœ์žญ์…˜

์‚ฌ์šฉ ๊ธฐ์ˆ 

  • ํ”„๋ก ํŠธ : React(Typescript)
  • ๋ฐฑ์—”๋“œ : Gin(Golang)
  • ๊ฒ€์ƒ‰ ์—”์ง„ & ์Šคํ† ๋ฆฌ์ง€ : Elastic Search
  • ๋ธ”๋ก์ฒด์ธ : Hyperledger Fabric, Fabric Gateway SDK
  • ํ…Œ์ŠคํŠธ : Jmeter, Postman

์•„ํ‚คํ…์ฒ˜ ๋ฐ ํ๋ฆ„๋„

์•„ํ‚คํ…์ฒ˜ ํ๋ฆ„๋„

๊ฐœ๋ฐœ

์ฝ”๋“œ

๊ฒŒ์ดํŠธ์›จ์ด ์—ฐ๊ฒฐ

func SetConnection() {
	log.Println("===============Set Connection ===============")
	clientConnection := newGrpcConnection()
	//defer clientConnection.Close()
	id := newIdentity()
	sign := newSign()

	gateway, err := client.Connect(
		id,
		client.WithSign(sign),
		client.WithClientConnection(clientConnection),
		client.WithEvaluateTimeout(5*time.Second),
		client.WithEndorseTimeout(15*time.Second),
		client.WithSubmitTimeout(5*time.Second),
		client.WithCommitStatusTimeout(1*time.Minute),
	)
	if err != nil {
		panic(err)
	}
	//defer gateway.Close()
	network := gateway.GetNetwork(channelName)
	ContractPass = network.GetContract(chaincodeName)
}

ํŠธ๋žœ์žญ์…˜

func TransferAsset(contract *client.Contract, transactionRequest TransactionRequest) string {
	log.Println(contract, "2", transactionRequest.AssetID, transactionRequest.NewOwner)

	submitResult, commit, err := contract.SubmitAsync("TransferAsset", client.WithArguments(transactionRequest.AssetID, transactionRequest.NewOwner))
	if err != nil {
		panic(fmt.Errorf("failed to submit transaction asynchronously: %w", err))
	}
	fmt.Printf("Successfully submitted transaction to transfer ownership from %s to %s. \n", string(submitResult), transactionRequest.NewOwner)

	if status, err := commit.Status(); err != nil {
		panic(fmt.Errorf("failed to get commit status: %w", err))
	} else if !status.Successful {
		panic(fmt.Errorf("transaction %s failed to commit with status: %d", status.TransactionID, int32(status.Code)))
	}
	return string(submitResult)
}

Elastic Search

type elasticClient struct {
	es        *elasticsearch.Client
	IndexName string
}

type ESResponse struct {
	Took int64
	Hits struct {
		Total struct {
			Value int64
		}
		Hits []*ESHit
	}
}

type ESHit struct {
	Score   float64 `json:"_score"`
	Index   string  `json:"_index"`
	Type    string  `json:"_type"`
	Version int64   `json:"_version,omitempty"`

	Source Article `json:"_source"`
}
func init() {
	cfg := esClientConfig()
	es, err := elasticsearch.NewClient(cfg)
	if err != nil {
		log.Printf("Error creating the client: %s", err)
	} else {
		log.Println(elasticsearch.Version)
		log.Println(es.Info())
	}
	esClient.es = es
	esClient.IndexName = "smart_contract"
}

func esClientConfig() elasticsearch.Config {
	cfg := elasticsearch.Config{
		Addresses:              []string{"https://localhost:9200"},
		APIKey:                 "ZkkwZ2dvWUJvNHBGMlQzZXVGZUU6eGJGaHpTY0JTWC1IU2ZvOTdHTk16QQ==",
		CertificateFingerprint: "6a220394bb428259b1991b3dcce16f7a810499de023d5d0bdb97c32bd762ba14",
	}
	//password : Zh-rgUV*3rdM6NhQE+Bo
	return cfg
}

Elastic Search ๊ฒ€์ƒ‰

func AddDocumentToES(item *Article) (string, error) {
	payload, err := json.Marshal(item)
	if err != nil {
		log.Println(err)
		return "", err
	}
	ctx := context.Background()
	req := esapi.IndexRequest{
		Index:      esClient.IndexName,
		DocumentID: string(item.ID),
		Body:       bytes.NewReader(payload),
		Refresh:    "true",
	}
	res, err := req.Do(ctx, esClient.es)
	if err != nil {
		log.Fatalf("Error getting rsponse: %s", err)
	}
	defer res.Body.Close()

	if res.IsError() {
		var e map[string]interface{}
		if err := json.NewDecoder(res.Body).Decode(&e); err != nil {
			log.Print("payload : ")
			log.Println(e)
			log.Println(err)
			return "", err
		}
		log.Print(e)
		return "", fmt.Errorf("[%s] %s: %s", res.Status(),
			e["error"].(map[string]interface{})["type"],
			e["error"].(map[string]interface{})["reason"])
	}

	return "Contract successfully added to search index", nil
}

ํ™”๋ฉด

์ •๋ณด

์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ
์—…๋กœ๋“œ

์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ
๋ฆฌ์ŠคํŠธ

์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ
์ƒ์„ธ ์ •๋ณด

์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ
๋น„๊ต

ํŠธ๋žœ์žญ์…˜
์ด๋ฒคํŠธ


ํ‰๊ฐ€

๋ณธ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ํ•˜์ดํผ๋ ˆ์ € ํŒจ๋ธŒ๋ฆญ ๋„คํŠธ์›Œํฌ์™€ ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด Fabric Gateway SDK๋ฅผ ํ™œ์šฉํ•˜์˜€์œผ๋ฉฐ,
๋ช…๋ น์–ด ๊ธฐ๋ฐ˜ ์‹คํ–‰๊ณผ SDK ๊ธฐ๋ฐ˜ ํŠธ๋žœ์žญ์…˜ ์„ฑ๋Šฅ์„ ํ‰๊ฐ€ํ•˜์˜€๋‹ค.

ํ…Œ์ŠคํŠธ ๋ฐฉ๋ฒ•

  • SDK
    • ํ”Œ๋žซํผ๊ณผ ์—ฐ๊ฒฐํ•˜๋Š” ์‹œ๊ฐ„์€ ํฌํ•จ๋˜์ง€ ์•Š์Œ.
    • REST API ์š”์ฒญ ->์‘๋‹ต ์‚ฌ์ด์˜ ์‹œ๊ฐ„์„ ์ธก์ •ํ•˜์˜€์Œ.
    • Jmeter๋ฅผ ํ™œ์šฉ
  • CLI
    • ์‹œ๊ฐ„ ์ธก์ •์€ ์„œ๋ฒ„์—์„œ CLI๋ฅผ ํ†ตํ•ด ์‰˜์Šคํฌ๋ฆฝํŠธ์— ์ž‘์„ฑ๋œ ๋ช…๋ น์–ด set์„ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์†Œ์š” ์‹œ๊ฐ„ ์ธก์ •
    • ๋ฐ˜๋ณต๋ฌธ-์‰˜์Šคํฌ๋ฆฝํŠธ -> ๋™์ž‘-์‰˜์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ๋ฐ˜๋ณต ์ˆ˜ํ–‰ํ•˜์˜€์Œ.
    • ๋ฐ์ดํ„ฐ๋Š” ํŒŒ์ดํ”„๋ผ์ธ์„ ํ†ตํ•ด ๊ธฐ๋กํ•˜๊ณ  ์ด๋ฅผ ์‰˜์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ†ตํ•ด min,avg,max ๋กœ ์ข…ํ•ฉ, ์ •๋ฆฌํ•จ.

ํŠน์ด์‚ฌํ•ญ

  • CLI ์ฒซ ๊ฐ’์˜ latency๊ฐ€ ๋งค์šฐ ํผ
    • ์•„๋งˆ connection ๋ฌธ์ œ์ผ ๋“ฏ, Gateway๋Š” connection pool์ด ์กด์žฌํ•จ.
    • 99% line์˜ ๊ฐ’๊ณผ maximum๊ฐ’์˜ ์ฐจ์ด๊ฐ€ ๋งค์šฐ ํผ, ์ด๋Š” ํ•œ ๊ฐ’์ด ๋งค์šฐ ํА์„ ์ถ”์ธกํ•  ์ˆ˜ ์žˆ์Œ.
    • => ๊ฒฐ๊ณผ์ ์œผ๋กœ ์ฒซ ๋ฒˆ์งธ ํŠ€๋Š” ๊ฐ’์„ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€๋“ค์„ ํ†ตํ•ด์„œ min,avg,max ๊ฐ’์„ ํ‰๊ฐ€ํ•จ.

Charts

img1 img2

์ „์ฒด ๋น„๊ต

์ตœ๋Œ€

img3 img4

ํ‰๊ท 

์ตœ์†Œ


๊ฒฐ๊ณผ

  • SDK๊ฐ€ CLI๋ณด๋‹ค ์„ฑ๋Šฅ์ด ๋›ฐ์–ด๋‚จ.
  • ์ด์œ 
    • Fabric Gateway SDK์˜ ๊ฒฝ์šฐ connection pooling ๋ฐฉ์‹์„ ํ†ตํ•ด ํŒจ๋ธŒ๋ฆญ ๋„คํŠธ์›Œํฌ์™€ ์—ฐ๊ฒฐ๋˜์–ด์žˆ์Œ.
    • ๊ทธ๋Ÿฌ๋‚˜, CLI์˜ ๊ฒฝ์šฐ ๋งค๋ฒˆ ๋…๋ฆฝ์ ์œผ๋กœ ์‹œํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋งค๋ฒˆ ํŒจ๋ธŒ๋ฆญ ๋„คํŠธ์›Œํฌ์™€ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ถ”์ธก

About

Taged based SmartContract Management System

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors