-
Notifications
You must be signed in to change notification settings - Fork 5
feat: virtual account #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ import ( | |
) | ||
|
||
type Sender struct { | ||
Name string | ||
Amount *big.Int | ||
Color string | ||
Account AccountValue | ||
Amount *big.Int | ||
Color string | ||
} | ||
|
||
type stack[T any] struct { | ||
|
@@ -76,15 +76,15 @@ func (s *fundsStack) compactTop() { | |
continue | ||
} | ||
|
||
if first.Name != second.Name || first.Color != second.Color { | ||
if first.Account != second.Account || first.Color != second.Color { | ||
return | ||
} | ||
Comment on lines
+79
to
81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAvoid interface equality that can panic for non-comparable AccountValue types; make equality explicit Comparing interface values with “!=” panics if the dynamic type is not comparable. Also, equality semantics may differ by implementation (string address vs virtual account identity). Use an explicit comparer. - if first.Account != second.Account || first.Color != second.Color {
+ if !accountsEqual(first.Account, second.Account) || first.Color != second.Color {
return
} Add helper (outside the shown range) and import reflect: import "reflect"
// accountsEqual defines equality semantics for AccountValue.
// - AccountAddress: value equality
// - pointer-backed implementations (e.g., virtual accounts): pointer identity
// - fallback: DeepEqual (safe for non-comparable structs)
func accountsEqual(a, b AccountValue) bool {
if a == nil || b == nil {
return a == b
}
ta, tb := reflect.TypeOf(a), reflect.TypeOf(b)
if ta != tb {
return false
}
va, vb := reflect.ValueOf(a), reflect.ValueOf(b)
switch ta.Kind() {
case reflect.String, reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.Bool:
return a == b
case reflect.Ptr, reflect.UnsafePointer:
return va.Pointer() == vb.Pointer()
default:
return reflect.DeepEqual(a, b)
}
} 🏁 Script executed: #!/bin/bash
set -eu
# Locate the definition of AccountValue
rg -nP 'type\s+AccountValue' -C3 -g '*.go'
# Preview imports in internal/interpreter/funds_stack.go
sed -n '1,50p' internal/interpreter/funds_stack.go
# Show context around lines 79-81
sed -n '60,100p' internal/interpreter/funds_stack.go
# Check whether reflect is already imported
rg -n 'reflect' internal/interpreter/funds_stack.go Length of output: 2974 🏁 Script executed: #!/bin/bash
set -eu
# Show AccountValue definition and its implementers in value.go
sed -n '1,200p' internal/interpreter/value.go
# Locate all types implementing the account() method
rg -nP '\.account\(' -C3 -g '*.go' Length of output: 4506 🏁 Script executed: #!/bin/bash
set -eu
# Locate the definition of VirtualAccount
rg -nP 'type\s+VirtualAccount\b' -C3 -g '*.go'
# If found, show its full definition (context +/-10 lines)
FILE_AND_LINE=$(rg -nP 'type\s+VirtualAccount\b' -n -g '*.go' | head -n1)
if [ -n "$FILE_AND_LINE" ]; then
FILE=$(echo "$FILE_AND_LINE" | cut -d: -f1)
LINE=$(echo "$FILE_AND_LINE" | cut -d: -f2)
start=$(( LINE > 10 ? LINE - 10 : 1 ))
sed -n "${start},$((LINE+10))p" "$FILE"
fi Length of output: 1415 Replace interface equality on AccountValue with explicit helper if !accountsEqual(first.Account, second.Account) || first.Color != second.Color {
return
} Import 🤖 Prompt for AI Agents
|
||
|
||
s.senders = &stack[Sender]{ | ||
Head: Sender{ | ||
Name: first.Name, | ||
Color: first.Color, | ||
Amount: new(big.Int).Add(first.Amount, second.Amount), | ||
Account: first.Account, | ||
Color: first.Color, | ||
Amount: new(big.Int).Add(first.Amount, second.Amount), | ||
}, | ||
Tail: s.senders.Tail.Tail, | ||
} | ||
|
@@ -152,19 +152,19 @@ func (s *fundsStack) Pull(requiredAmount *big.Int, color *string) []Sender { | |
case 1: // more than enough | ||
s.senders = &stack[Sender]{ | ||
Head: Sender{ | ||
Name: available.Name, | ||
Color: available.Color, | ||
Amount: new(big.Int).Sub(available.Amount, requiredAmount), | ||
Account: available.Account, | ||
Color: available.Color, | ||
Amount: new(big.Int).Sub(available.Amount, requiredAmount), | ||
}, | ||
Tail: s.senders, | ||
} | ||
fallthrough | ||
|
||
case 0: // exactly the same | ||
out = append(out, Sender{ | ||
Name: available.Name, | ||
Color: available.Color, | ||
Amount: new(big.Int).Set(requiredAmount), | ||
Account: available.Account, | ||
Color: available.Color, | ||
Amount: new(big.Int).Set(requiredAmount), | ||
}) | ||
return out | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Flag added and wired into AllFlags — LGTM. Also verify usage coverage.
Run to confirm the flag is actually gating features and tests:
Also applies to: 24-25
🏁 Script executed:
Length of output: 1295
Add unit tests for ExperimentalVirtualAccount gating
_test.go
files referenceExperimentalVirtualAccount
; add tests covering both enabled and disabled scenarios to ensure the flag actually gates behavior.🤖 Prompt for AI Agents