Update main.go
This commit is contained in:
parent
a8f460388a
commit
fa3309a4bd
1 changed files with 20 additions and 19 deletions
39
main.go
39
main.go
|
|
@ -126,9 +126,9 @@ type PromiseTxBody struct {
|
||||||
Type string `json:"type"` // "promise"
|
Type string `json:"type"` // "promise"
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Due int64 `json:"due"`
|
Due int64 `json:"due,omitempty"`
|
||||||
BeneficiaryID string `json:"beneficiary_id"`
|
BeneficiaryID string `json:"beneficiary_id,omitempty"`
|
||||||
ParentPromiseID *string `json:"parent_promise_id"`
|
ParentPromiseID *string `json:"parent_promise_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitmentTxBody struct {
|
type CommitmentTxBody struct {
|
||||||
|
|
@ -136,7 +136,7 @@ type CommitmentTxBody struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
PromiseID string `json:"promise_id"`
|
PromiseID string `json:"promise_id"`
|
||||||
CommiterID string `json:"commiter_id"`
|
CommiterID string `json:"commiter_id"`
|
||||||
Due int64 `json:"due"`
|
Due int64 `json:"due,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SignedTx struct {
|
type SignedTx struct {
|
||||||
|
|
@ -237,16 +237,17 @@ func createPromiseAndCommit(args CreatePromiseArgs, rpcURL string) error {
|
||||||
if args.Text == "" {
|
if args.Text == "" {
|
||||||
return errors.New("--text is required")
|
return errors.New("--text is required")
|
||||||
}
|
}
|
||||||
if args.BeneficiaryID == "" {
|
//if args.BeneficiaryID == "" {
|
||||||
return errors.New("--beneficiary-id is required")
|
// return errors.New("--beneficiary-id is required")
|
||||||
}
|
//}
|
||||||
promiseDue, err := parseWhen(args.DueISO)
|
var due int64
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("promise --due: %w", err)
|
if args.CommitmentDueISO != "" {
|
||||||
}
|
var err error
|
||||||
commitDue, err := parseWhen(args.CommitmentDueISO)
|
due, err = parseWhen(args.CommitmentDueISO)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("commitment --commitment-due: %w", err)
|
return fmt.Errorf("promise --due: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub, priv, err := ensureKeypair()
|
pub, priv, err := ensureKeypair()
|
||||||
|
|
@ -269,7 +270,7 @@ func createPromiseAndCommit(args CreatePromiseArgs, rpcURL string) error {
|
||||||
Type: "promise",
|
Type: "promise",
|
||||||
ID: promiseID,
|
ID: promiseID,
|
||||||
Text: args.Text,
|
Text: args.Text,
|
||||||
Due: promiseDue,
|
Due: due,
|
||||||
BeneficiaryID: args.BeneficiaryID,
|
BeneficiaryID: args.BeneficiaryID,
|
||||||
ParentPromiseID: parentPtr,
|
ParentPromiseID: parentPtr,
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +279,7 @@ func createPromiseAndCommit(args CreatePromiseArgs, rpcURL string) error {
|
||||||
ID: commitmentID,
|
ID: commitmentID,
|
||||||
PromiseID: promiseID,
|
PromiseID: promiseID,
|
||||||
CommiterID: commiterID,
|
CommiterID: commiterID,
|
||||||
Due: commitDue,
|
Due: due,
|
||||||
}
|
}
|
||||||
|
|
||||||
var compound CompositeSignedTx
|
var compound CompositeSignedTx
|
||||||
|
|
@ -431,8 +432,8 @@ func sendMain(args []string) {
|
||||||
fmt.Printf("✅ Beneficiary created: %s\n", id)
|
fmt.Printf("✅ Beneficiary created: %s\n", id)
|
||||||
default:
|
default:
|
||||||
// promise+commitment
|
// promise+commitment
|
||||||
if text == "" || due == "" || beneficiaryID == "" || commitmentDue == "" {
|
if text == "" /* || due == "" || beneficiaryID == "" || commitmentDue == "" */ {
|
||||||
fmt.Fprintln(os.Stderr, "⛔ For promise+commitment you must pass --text, --due, --beneficiary-id, --commitment-due")
|
fmt.Fprintln(os.Stderr, "⛔ For promise+commitment you must pass --text")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
args := CreatePromiseArgs{
|
args := CreatePromiseArgs{
|
||||||
|
|
@ -440,7 +441,7 @@ func sendMain(args []string) {
|
||||||
DueISO: due,
|
DueISO: due,
|
||||||
BeneficiaryID: beneficiaryID,
|
BeneficiaryID: beneficiaryID,
|
||||||
ParentPromiseID: parentID,
|
ParentPromiseID: parentID,
|
||||||
CommitmentDueISO: commitmentDue,
|
CommitmentDueISO: due,
|
||||||
}
|
}
|
||||||
if err := createPromiseAndCommit(args, rpc); err != nil {
|
if err := createPromiseAndCommit(args, rpc); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "❌ Error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "❌ Error: %v\n", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue