github.com/0chain/gosdk@v1.17.11/wasmsdk/demo/main.go (about)

     1  // Demo for the wasm sdk- do not use.
     2  package main
     3  
     4  import (
     5  	"context"
     6  	"log"
     7  	"net/http"
     8  	"sync"
     9  
    10  	"github.com/0chain/gosdk/core/common"
    11  	"github.com/0chain/gosdk/zcncore"
    12  	"github.com/uptrace/bunrouter"
    13  )
    14  
    15  func main() {
    16  
    17  	zcncore.InitSignatureScheme("bls0chain")
    18  	
    19  	ctx, cf := context.WithCancel(context.Background())
    20  
    21  	router := bunrouter.New()
    22  
    23  	router.GET("/shutdown", func(w http.ResponseWriter, req bunrouter.Request) error {
    24  		log.Println("wasm:shutdown")
    25  		cf()
    26  		return nil
    27  	})
    28  
    29  	// create a new wallet
    30  	router.POST("/wallet", func(w http.ResponseWriter, req bunrouter.Request) error {
    31  
    32  		wallet, err := zcncore.CreateWalletOffline()
    33  
    34  		if err != nil {
    35  			return err
    36  		}
    37  
    38  		w.WriteHeader(http.StatusOK)
    39  		w.Write([]byte(wallet))
    40  
    41  		return nil
    42  	})
    43  
    44  	fileServer := http.FileServer(http.Dir("./"))
    45  
    46  	router.GET("/*path", bunrouter.HTTPHandler(fileServer))
    47  
    48  	go func() {
    49  		log.Println("wasm: listening on http://127.0.0.1:8080")
    50  		log.Println(http.ListenAndServe(":8080", router))
    51  
    52  	}()
    53  
    54  	<-ctx.Done()
    55  
    56  }
    57  
    58  type statusBar struct {
    59  	walletString string
    60  	wg           *sync.WaitGroup
    61  	success      bool
    62  	errMsg       string
    63  	balance      common.Balance
    64  	nonce        int64
    65  	wallets      []string
    66  	clientID     string
    67  }