MCPcopy Create free account
hub / github.com/chain/Core / insertControlProgramDelayed

Method insertControlProgramDelayed

core/account/builder.go:214–236  ·  view source on GitHub ↗

insertControlProgramDelayed takes a template builder and an account control program that hasn't been inserted to the database yet. It registers callbacks on the TemplateBuilder so that all of the template's account control programs are batch inserted if building the rest of the template is successfu

(ctx context.Context, b *txbuilder.TemplateBuilder, acp *controlProgram)

Source from the content-addressed store, hash-verified

212// account control programs are batch inserted if building the rest of
213// the template is successful.
214func (m *Manager) insertControlProgramDelayed(ctx context.Context, b *txbuilder.TemplateBuilder, acp *controlProgram) {
215 m.delayedACPsMu.Lock()
216 m.delayedACPs[b] = append(m.delayedACPs[b], acp)
217 m.delayedACPsMu.Unlock()
218
219 b.OnRollback(func() {
220 m.delayedACPsMu.Lock()
221 delete(m.delayedACPs, b)
222 m.delayedACPsMu.Unlock()
223 })
224 b.OnBuild(func() error {
225 m.delayedACPsMu.Lock()
226 acps := m.delayedACPs[b]
227 delete(m.delayedACPs, b)
228 m.delayedACPsMu.Unlock()
229
230 // Insert all of the account control programs at once.
231 if len(acps) == 0 {
232 return nil
233 }
234 return m.insertAccountControlProgram(ctx, acps...)
235 })
236}

Callers 2

BuildMethod · 0.80
BuildMethod · 0.80

Calls 4

deleteFunction · 0.85
OnRollbackMethod · 0.80
OnBuildMethod · 0.80

Tested by

no test coverage detected