Skip to content

Commit

Permalink
request deposit entries command
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Jul 25, 2024
1 parent 75ff1da commit 3eb3d32
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
57 changes: 57 additions & 0 deletions cli/deposit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"context"
"encoding/json"
"fmt"
"os"
"strings"

"github.com/MixinNetwork/bot-api-go-client/v3"
"github.com/urfave/cli/v2"
)

var requestDepositEntryCmdCli = &cli.Command{
Name: "requestdepositentry",
Action: requestDepositEntry,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "keystore,k",
Usage: "keystore download from https://developers.mixin.one/dashboard",
},
&cli.StringFlag{
Name: "chain",
Usage: "the chain id",
},
&cli.StringFlag{
Name: "members",
Usage: "comma separated UUIDs",
},
&cli.Int64Flag{
Name: "threshold",
Usage: "the members threshold",
},
},
}

func requestDepositEntry(c *cli.Context) error {
ctx := context.Background()

dat, err := os.ReadFile(c.String("keystore"))
if err != nil {
panic(err)
}
var su bot.SafeUser
err = json.Unmarshal([]byte(dat), &su)
if err != nil {
panic(err)
}

members := strings.Split(c.String("members"), ",")
entries, err := bot.CreateDepositEntry(ctx, c.String("chain"), members, c.Int64("threshold"), &su)
if err != nil {
return err
}
fmt.Println(entries[0])
return nil
}
8 changes: 5 additions & 3 deletions cli/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ func ClaimMintDistribution(c *cli.Context) error {
if err != nil {
return err
}
if mints[0].Inputs[0].Mint.Batch != c.Uint64("batch") {
panic(mints[0].PayloadHash().String())
if b := mints[0].Inputs[0].Mint.Batch; b != c.Uint64("batch") {
fmt.Printf("MINT %s %d %d", mints[0].PayloadHash(), b, c.Uint64("batch"))
return nil
}

safe, err := rpc.GetUTXO(KernelRPC, mints[0].PayloadHash().String(), uint64(len(mints[0].Outputs)-2))
Expand Down Expand Up @@ -261,7 +262,8 @@ func ClaimMintDistribution(c *cli.Context) error {
})
}
change := total.Sub(outputTotal)
if change.String() == "0.00000001" {
threshold := common.NewIntegerFromString("0.00000005")
if change.Sign() > 0 && change.Cmp(threshold) < 0 {
r := recipients[len(recipients)-1]
r.Amount = common.NewIntegerFromString(r.Amount).Add(change).String()
}
Expand Down
1 change: 1 addition & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func main() {
safeOutputsCmdCli,
safeOutputCmdCli,
withdrawalCmdCli,
requestDepositEntryCmdCli,
spendKernelUTXOsCmdCli,
claimMintDistributionCmdCli,
},
Expand Down
3 changes: 3 additions & 0 deletions safe_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func RegisterSafe(ctx context.Context, userId, seed string, su *SafeUser) (*User
if err != nil {
return nil, err
}
if su.SpendPrivateKey != hex.EncodeToString(private) {
panic("please use the same spend private key with tip private key")
}
sigBuf := ed25519.Sign(ed25519.PrivateKey(pinBuf), tipBody)

encryptedPIN, err := EncryptEd25519PIN(hex.EncodeToString(sigBuf), uint64(time.Now().UnixNano()), su)
Expand Down

0 comments on commit 3eb3d32

Please sign in to comment.