func (s *PeerState) ProcessHello(hello *protocol.Hello) error { s.mu.Lock() defer s.mu.Unlock() s.CurrentLedger = hello.GetLedgerIndex() s.Name = hello.GetFullVersion() s.MajorVersion = hello.GetProtoVersion() s.MinorVersion = hello.GetProtoVersionMin() var err error s.PublicKey, err = crypto.NewRippleHash(string(hello.NodePublic)) if err != nil { s.Status = HelloFailed return fmt.Errorf("Bad node public key: %s", hello.NodePublic) } s.Status = Verified return nil }
func NewAmount(v interface{}) (*Amount, error) { switch n := v.(type) { case int64: return &Amount{ Value: NewValue(true, n < 0, abs(n), 0), }, nil case string: amount := &Amount{ Value: &Value{}, } var err error parts := strings.Split(n, "/") if len(parts) == 1 { amount.Native = true } if len(parts) > 1 && parts[1] == "XRP" { amount.Native = true if !strings.Contains(parts[0], ".") { parts[0] = parts[0] + "." } } if amount.Parse(parts[0]); err != nil { return nil, err } if len(parts) > 1 { if amount.Currency, err = NewCurrency(parts[1]); err != nil { return nil, err } } if len(parts) > 2 { if issuer, err := crypto.NewRippleHash(parts[2]); err != nil { return nil, err } else { copy(amount.Issuer[:], issuer.Payload()) } } return amount, nil default: return nil, fmt.Errorf("Bad type: %+v", v) } }