Esempio n. 1
0
func PublicKeyStringToECAddressString(public string) (string, error) {
	pubHex, err := hex.DecodeString(public)
	if err != nil {
		return "", err
	}

	add, err := PublicKeyToECAddress(pubHex)
	if err != nil {
		return "", err
	}

	return primitives.ConvertECAddressToUserStr(add), nil
}
Esempio n. 2
0
// Make this into somewhat readable text.
func (ta TransAddress) CustomMarshalTextAll(fct bool, label string) ([]byte, error) {
	var out bytes.Buffer
	out.WriteString(fmt.Sprintf("   %8s:", label))
	v := primitives.ConvertDecimalToPaddedString(ta.Amount)
	fill := 8 - len(v) + strings.Index(v, ".") + 1
	fstr := fmt.Sprintf("%%%vs%%%vs ", 18-fill, fill)
	out.WriteString(fmt.Sprintf(fstr, v, ""))
	if fct {
		out.WriteString(primitives.ConvertFctAddressToUserStr(ta.Address))
	} else {
		out.WriteString(primitives.ConvertECAddressToUserStr(ta.Address))
	}
	str := fmt.Sprintf("\n                  %016x %038s\n\n", ta.Amount, string(hex.EncodeToString(ta.GetAddress().Bytes())))
	out.WriteString(str)
	return out.Bytes(), nil
}
Esempio n. 3
0
func HandleV2GetPendingTransactions(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
	fmt.Println("HandleV2GetPendingTransactions")
	type PendingTransactions struct {
		TransactionID interfaces.IHash
		Inputs        []interfaces.IInAddress
		Outputs       []interfaces.IOutAddress
		ECOutputs     []interfaces.IOutECAddress
	}
	pending := state.GetPendingTransactions()
	resp := make([]PendingTransactions, len(pending))
	var uAddr string
	var uIAddr interfaces.IAddress
	for i, tran := range pending {
		resp[i].TransactionID = tran.GetSigHash()

		resp[i].Inputs = tran.GetInputs()
		resp[i].Outputs = tran.GetOutputs()
		resp[i].ECOutputs = tran.GetECOutputs()

		for k, _ := range resp[i].Inputs {
			uIAddr = resp[i].Inputs[k].GetAddress()
			uAddr = primitives.ConvertFctAddressToUserStr(uIAddr)
			resp[i].Inputs[k].SetUserAddress(uAddr)
		}
		for k, _ := range resp[i].Outputs {
			uIAddr = resp[i].Outputs[k].GetAddress()
			uAddr = primitives.ConvertFctAddressToUserStr(uIAddr)
			resp[i].Outputs[k].SetUserAddress(uAddr)
		}

		for k, _ := range resp[i].ECOutputs {
			uIAddr = resp[i].ECOutputs[k].GetAddress()
			uAddr = primitives.ConvertECAddressToUserStr(uIAddr)
			resp[i].ECOutputs[k].SetUserAddress(uAddr)

		}

	}
	return resp, nil
}
Esempio n. 4
0
func Test_Entry_Credit_Addresses(test *testing.T) {

	addr := NewAddress(primitives.Sha([]byte("A fake address")).Bytes())

	uaddr := primitives.ConvertECAddressToUserStr(addr)

	if !primitives.ValidateECUserStr(uaddr) {
		fmt.Printf("1")
		test.Fail()
	}

	addrBack := primitives.ConvertUserStrToAddress(uaddr)

	if bytes.Compare(addrBack, addr.Bytes()) != 0 {
		fmt.Printf("2")
		test.Fail()
	}

	buaddr := []byte(uaddr)

	for i, v := range buaddr {
		for j := uint(0); j < 8; j++ {
			if !primitives.ValidateECUserStr(string(buaddr)) {
				fmt.Printf("3")
				test.Fail()
				return
			}
			buaddr[i] = v ^ (01 << j)
			if primitives.ValidateECUserStr(string(buaddr)) {
				fmt.Printf("4")
				test.Fail()
				return
			}
			buaddr[i] = v
		}
	}
}